#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n;
int main() {
  std ::ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long ans = 0;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    mp[p]++;
    ans += p;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int x_count = mp[x];
    ans -= x_count * x;
    ans += x_count * y;
    mp[x] = 0;
    mp[y] += x_count;
    cout << ans << endl;
  }
  return 0;
}
