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