#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int a[N], avail[N];
int n, q;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum + a[i];
    avail[a[i]]++;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum = sum - b * avail[b];
    sum = sum + c * avail[b];
    avail[c] += avail[b];
    avail[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
