#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  ll s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    if (!mp.count(a[i])) {
      mp[a[i]] = 1;
    } else {
      mp[a[i]]++;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int k = mp[b];
    s = s - k * b + k * c;
    cout << s << endl;
    mp[b] = 0;
    if (!mp.count(c))
      mp[c] = k;
    else {
      mp[c] += k;
    }
  }
  return 0;
}
