#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, inp, sum = 0, b, c;
  cin >> n;
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> inp;
    mp[inp]++;
    sum = sum + inp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum += (c - b) * mp[b];
    mp[c]++;
    mp[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
