#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    if (mp.find(x) == mp.end()) {
      cout << sum << endl;
      continue;
    }
    int z = mp[x];
    mp[x] = 0;
    mp[y] = mp[y] + z;
    sum = sum - z * x + z * y;
    cout << sum << endl;
  }
}
