#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n], sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  int q, aa, b;
  cin >> q;
  while (q--) {
    cin >> aa >> b;
    sum = sum - mp[aa] * aa + mp[aa] * b;
    mp[b] += mp[aa];
    mp[aa] = 0;
    cout << sum << endl;
  }
  return 0;
}
