#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, s = 0, q;
  cin >> n;
  int A[100001] = {0};
  for (int i = 1; i <= n; i++) {
    cin >> x;
    A[x]++;
    s += x;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    A[y] += A[x];
    s += y * A[x] - x * A[x];
    A[x] = 0;
    cout << s << endl;
  }
}
