#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  long long s = 1, c;
  while (a && b) {
    if ((~a & 1) && (~b & 1))
      a >>= 1, b >>= 1, s <<= 1;
    else if (~a & 1)
      a >>= 1;
    else if (~b & 1)
      b >>= 1;
    else if (a > b)
      a = a - b;
    else
      c = b - a, b = a, a = c;
  }
  if (!a) return b * s;
  if (!b) return a * s;
}
using namespace std;
int main() {
  long long ans = 0;
  int s[100001] = {0};
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s[a[i]]++;
  }
  int m;
  cin >> m;
  int b[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 1; i <= 100000; i++) {
    ans += s[i] * i;
  }
  for (int i = 0; i < m; i++) {
    ans += s[b[i]] * (c[i]);
    s[c[i]] += s[b[i]];
    ans -= s[b[i]] * b[i];
    s[b[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
