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