#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
signed main() {
  long long n;
  cin >> n;
  long long sb[N];
  long long sum = 0;
  map<long long, long long> kk;
  for (long long i = 1; i <= n; i++) {
    cin >> sb[i];
    sum += sb[i];
    kk[sb[i]]++;
  }
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    kk[b] += kk[a];
    sum += (b - a) * kk[a];
    cout << sum << "\n";
  }
}
