#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n;
  cin >> n;
  int64_t sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum += a;
    mp[a]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (!mp.count(b) || mp[b] == 0) {
      cout << sum << '\n';
    } else {
      sum -= mp[b] * b;
      sum += mp[b] * c;
      mp[c] += mp[b];
      mp[b] = 0;
      cout << sum << "\n";
    }
  }
  return 0;
}
