#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      sum += (c - b) * mp[b];
      mp[c] += mp[b];
    }
    cout << sum;
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
