#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int t;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> t;
    mp[t] += 1;
  }
  long long total = 0;
  for (int i = 0; i < (int)(10); ++i) {
    total += i * mp[i];
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < (int)(q); ++i) {
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    long long total = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      total += itr->first * itr->second;
    }
    cout << total << endl;
  }
}
