#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c, i, k, sum = 0;
  int a[100001];
  cin >> n;
  for (i = 1; i <= 100000; i++) a[i] = 0;
  for (i = 1; i <= n; i++) {
    cin >> k;
    a[k]++;
    sum += k;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (a[b] == 0)
      cout << sum << endl;
    else {
      a[c] += a[b];
      sum = sum + c * a[b] - b * a[b];
      a[b] = 0;
      cout << sum << endl;
    }
  }
  return 0;
}
