#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    long long n, a[100002], b[100003], q, sum = 0, l, r;
    cin >> n;
    for (int i = 0; i <= n - 1; i++) {
      cin >> a[i];
      b[a[i]]++;
      sum += a[i];
    }
    cin >> q;
    for (int i = 0; i <= q - 1; i++) {
      cin >> l >> r;
      sum += (r - l) * b[l];
      b[r] += b[l];
      cout << sum << "\n";
    }
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
