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