#include <bits/stdc++.h>
using namespace std;
long long kiran_bhanushali[29][7][20];
using graph = vector<vector<long long>>;
int32_t main() {
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    map<long long, long long> mp;
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      sum += x;
      mp[x]++;
    }
    long long q;
    cin >> q;
    while (q--) {
      long long x, y;
      cin >> x >> y;
      if (mp[x]) {
        long long c = mp[x];
        sum += y * c - x * c;
        mp[y] += c;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
