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