#include <bits/stdc++.h>
using namespace std;
int main() {
  int num, que;
  int tmp, tmp2;
  int minus;
  int bef, aft;
  long long sum = 0;
  map<int, int> m;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> tmp;
    m[tmp]++;
    sum += tmp;
  }
  cin >> que;
  for (int i = 0; i < que; i++) {
    cin >> bef >> aft;
    tmp = m[bef];
    if (tmp == 0) {
      cout << sum << endl;
      continue;
    }
    sum -= tmp * bef;
    sum += tmp * aft;
    m[bef] = 0;
    m[aft] += tmp;
    cout << sum << endl;
  }
}
