#include <bits/stdc++.h>
using namespace std;
long long mul(long long a, long long b) {
  return (((a % 1000000007) * (b % 1000000007)) % 1000000007);
}
long long modexp(long long b, long long e) {
  long long res = 1;
  for (; e; b = b * b % 1000000007, e >>= 1)
    if (e & 1) res = res * b % 1000000007;
  return res;
}
long long modinv(long long a) {
  long long x = 1000000007 - 2;
  return modexp(a, x);
}
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0, max = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ;
    sum += a[i];
  }
  long long hash[10001] = {0};
  for (long long i = 0; i < n; i++) hash[a[i]]++;
  long long q;
  cin >> q;
  ;
  vector<long long> ans;
  for (long long i = 0; i < q; i++) {
    long long b;
    cin >> b;
    ;
    long long c;
    cin >> c;
    ;
    sum -= hash[b] * b;
    sum += hash[b] * c;
    hash[c] += hash[b];
    hash[b] = 0;
    ans.push_back(sum);
  }
  for (long long i = 0; i < q; i++) cout << ans[i] << endl;
  return 0;
}
