#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  map<int, int> mp;
  cin >> N;
  int sum1 = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (mp.find(a) == mp.end())
      mp[a] = 1;
    else
      mp[a]++;
    sum1 += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    sum1 -= (b * mp[b]);
    if (mp.find(c) == mp.end())
      mp[c] = mp[b];
    else
      mp[c] += mp[b];
    sum1 += (c * mp[b]);
    mp.erase(b);
    cout << sum1 << "\n";
  }
  return 0;
}
