#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  int cursum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cursum += x;
    m[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int num = m[b];
    m[b] = 0;
    m[c] += num;
    cursum -= b * num;
    cursum += c * num;
    cout << cursum << endl;
  }
  return 0;
}
