#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n), nms(100005);
  long long ttl = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    nms[v[i]]++;
    ttl += v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    ttl -= nms[b] * b;
    ttl += nms[b] * c;
    nms[c] += nms[b];
    nms[b] = 0;
    cout << ttl << '\n';
  }
  return 0;
}
