#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
  int n, q;
  cin >> n;
  int a[n], g[100000] = {0};
  long long s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    g[a[i]]++;
    s += a[i];
  }
  cin >> q;
  int b[q], c[q];
  for (i = 0; i < q; i++) cin >> b[i] >> c[i];
  for (i = 0; i < q; i++) {
    if (c[i] - b[i] >= 0) s += g[b[i]] * (c[i] - b[i]);
    if (c[i] - b[i] < 0) s -= g[b[i]] * (b[i] - c[i]);
    g[c[i]] += g[b[i]];
    cout << s << endl;
  }
  return 0;
}
