#include <bits/stdc++.h>
using namespace std;
long long binpow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long binpowmod(long long x, long long y, long long p) {
  unsigned long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long mod_inverse(long long n, long long p) {
  return binpowmod(n, p - 2, p);
}
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool comp(pair<int, int> x, pair<int, int> y) { return x.first < y.first; }
bool comp_pairs_by_s(pair<long long, long long> &x,
                     pair<long long, long long> &y) {
  return x.second < y.second;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
class cmp {
 public:
  bool operator()(pair<int, int> A, pair<int, int> B) {
    if (abs(A.first - A.second) == abs(B.first - B.second))
      return A.first > B.first;
    return abs(A.first - A.second) < abs(B.first - B.second);
  }
};
int prime[1768457] = {0};
void sieve(void) {
  int i, j;
  for (i = 0; i < 1768457; i++) prime[i] = 1;
  prime[0] = 0, prime[1] = 0;
  for (i = 2; i <= sqrt(1768457); i++) {
    if (prime[i]) {
      for (j = i * i; j < 1768457; j += i) {
        prime[j] = 0;
      }
    }
  }
}
void swap(long long &x, long long &y) {
  int temp = x;
  x = y;
  y = temp;
}
unsigned int onesComplement(unsigned int n) {
  int number_of_bits = floor(log2(n)) + 1;
  return ((1 << number_of_bits) - 1) ^ n;
}
void solve() {
  int n;
  cin >> n;
  unordered_map<int, int> m;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    m[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end() || m[b] != 0) {
      int cnt = m[b];
      m[b] = 0;
      m[c] += cnt;
      sum = sum - cnt * b + cnt * c;
    }
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
