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