#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  map<int, int> mp;
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  ll sum = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    sum += i->first * i->second;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    int n_b = mp[b];
    if (n_b == 0) {
      cout << sum << endl;
      continue;
    }
    mp[b] = 0;
    mp[c] += n_b;
    sum += (c - b) * n_b;
    cout << sum << endl;
  }
  return 0;
}
