#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), num(100010, 0);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    num[a[i]]++;
  }
  int t = accumulate(a.begin(), a.end(), 0);
  int q, b, c;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    cin >> b >> c;
    int bNum = num[b];
    t -= num[b] * b;
    num[c] += num[b];
    num[b] = 0;
    t += c * bNum;
    cout << t << endl;
  }
  return 0;
}
