#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < (n); i++) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    if (mp.find(b) == mp.end())
      cout << sum << endl;
    else {
      sum = sum - b * mp[b] + c * mp[b];
      mp[c] += mp[b];
      mp.erase(b);
      cout << sum << endl;
    }
  }
}
