#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n, x;
  cin >> n;
  long long s = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> x;
    s += x;
    mp[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    mp[b] += mp[a];
    s = s - mp[a] * a + mp[a] * b;
    mp[a] = 0;
    cout << s << '\n';
  }
  return 0;
}
