#include <bits/stdc++.h>
using namespace std;
int main() {
  int index[100001] = {0}, n, q, i, j, tmp;
  cin >> n;
  long long int a[n], sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    index[a[i]]++;
  }
  cin >> q;
  int b[q][2];
  for (i = 0; i < q; i++)
    for (j = 0; j < 2; j++) cin >> b[i][j];
  for (i = 0; i < q; i++) {
    tmp = index[b[i][0]];
    if (tmp) {
      sum = sum - (tmp * (b[i][0]));
      index[b[i][0]] = 0;
      sum = sum + (tmp * (b[i][1]));
      index[b[i][1]] += tmp;
    }
    cout << sum << "\n";
  }
  return 0;
}
