#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  long arr[n], sum = 0;
  unordered_map<long, long> ma;
  for (long i = 0; i < n; i++) {
    cin >> arr[i];
    ma[arr[i]]++;
    sum += arr[i];
  }
  long q;
  cin >> q;
  for (long k = 0; k < q; k++) {
    long a, b, temp;
    cin >> a >> b;
    temp = ma[a];
    sum -= (temp * a);
    sum += (temp * b);
    cout << sum << "\n";
    if (ma.find(b) != ma.end())
      ma[b] = ma[b] + temp;
    else
      ma.insert({b, temp});
  }
  return 0;
}
