#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<long long> buf;
void permutation(long long i, const long long size, const long long range_start,
                 const long long range_end) {
  if (i == size) {
    for (long long itr : buf) {
      cout << itr;
    }
  } else {
    for (long long j = range_start; j <= range_end; ++j) {
      buf[i] = j;
      permutation(i + 1, size, range_start, range_end);
    }
  }
}
int main(void) {
  long long n, a, q, b, c, ans = 0;
  unordered_map<long long, long long> mp;
  cin >> n;
  for (long long i = 0; i < (n); i++) {
    cin >> a;
    mp[a]++;
  }
  cin >> q;
  for (long long i = 0; i < (q); i++) {
    ans = 0;
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      ans += itr->first * itr->second;
    }
    cout << ans << endl;
  }
  return 0;
}
