#include <bits/stdc++.h>
using namespace std;
int n;
int q;
int a[100010];
long long cnt = 0;
map<long long, long long> mp;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  while (q--) {
    int k, j;
    cin >> k >> j;
    cnt -= k * mp[k];
    cnt += j * mp[k];
    mp[j] += mp[k];
    cout << cnt << endl;
  }
  return 0;
}
