#include <bits/stdc++.h>
using namespace std;
void show(map<long long, long long> mp) {
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    if (itr->second != 0) {
      printf("%d: %d, ", itr->first, itr->second);
    }
  }
  printf("\n");
}
int main() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long 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];
  }
  long long q;
  cin >> q;
  long long b, c;
  for (int i = 0; i < (int)(q); ++i) {
    cin >> b >> c;
    mp[c] += mp[b];
    mp.erase(b);
    long long total = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      total += itr->first * itr->second;
    }
    cout << total << endl;
  }
}
