#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(1000005);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vec[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  vector<pair<int, int>> vp(q);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    vp[i].first = b;
    vp[i].second = c;
  }
  for (int i = 0; i < q; i++) {
    int b = vp[i].first, c = vp[i].second;
    vec[c] += vec[b];
    sum = sum - (long long)(b * vec[b]) + (long long)(c * vec[b]);
    vec[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
