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