#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  map<int, int> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    sum += x;
    m[x]++;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= m[b] * b;
    sum += m[b] * c;
    m[c] += m[b];
    m[b] = 0;
    cout << sum << endl;
  }
}
