#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y);
long long gcd(long long a, long long b);
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  long long s = 0;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    m[a[i]]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long xx = m[b];
    m[c] = xx;
    long long yy = xx * b;
    long long zz = xx * c;
    s -= yy;
    s += zz;
    cout << s << "\n";
    m[b] = 0;
  }
}
long long power(long long x, long long y) {
  long long res = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
