#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n;
  cin >> n;
  unsigned long long arr[n], sum = 0;
  unordered_map<unsigned long long, unsigned long long> ma;
  for (unsigned long long i = 0; i < n; i++) {
    cin >> arr[i];
    ma[arr[i]]++;
    sum += arr[i];
  }
  unsigned long long q;
  cin >> q;
  for (unsigned long long k = 0; k < q; k++) {
    unsigned long 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;
}
