#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, x, j, mx = 0, t, k, b, a, ans = 0, c = 0;
  string s, str;
  char strn;
  cin >> n;
  long long int ara[n + 1], bra[n + 1], taj[n + 1];
  map<long long int, long long int> mp;
  for (i = 1; i <= n; i++) {
    cin >> ara[i];
    ans += ara[i];
    mp[ara[i]]++;
  }
  cin >> k;
  while (k--) {
    cin >> a >> b;
    c = mp[a];
    ans += ((b - a) * c);
    mp[b] += c;
    cout << ans << endl;
  }
  return 0;
}
