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