using System;
using System.Collections.Generic;

class Program
{
  static int n;
  static int[] a;
  static int sum;
  static void Main()
  {
    n = int.Parse(Console.ReadLine());
    var line = Console.ReadLine();
    var _line = line.Split(" ");
    a = new int[n];
    for (int i = 0;i<n;i++)
    {
      a[i] = int.Parse(_line[i]);
    }
    int q = int.Parse(Console.ReadLine());
    int[] b = new int [q];
    int[] c = new int [q];
    for (int i=0;i<q;i++)
    {
      line = Console.ReadLine();
      _line = line.Split(" ");
      b[i] = int.Parse(_line[0]);
      c[i] = int.Parse(_line[1]);
      Console.WriteLine(Calc(a,b[i],c[i]));
    }
    
  }
  
  static int Calc(int[] _a, int _b, int _c)
  {
    sum = 0;
    for (int i = 0; i < n;i++)
    {
      _a[i] = (_a[i] == _b) ? _c : _a[i];
      sum += _a[i];
    }
    return sum;
  }
}