#include <bits/stdc++.h>
using namespace std;
int n, q, m, x, y;
long long sum = 0;
int c[100050];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    c[m]++;
    sum += m;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    sum += c[x] * y;
    sum -= c[x] * x;
    c[y] += c[x];
    c[x] = 0;
    cout << sum << endl;
  }
  return 0;
}
