#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  int n, q, a;
  cin >> n;
  vector<int> x(100001, 0);
  for (int i = 1; i <= (int)(n); i++) {
    cin >> a;
    x[a]++;
  }
  cin >> q;
  vector<int> b(q + 1), c(q + 1), s(q + 1, 0);
  for (int i = 1; i <= (int)(100000); i++) s[0] += i * x[i];
  int A, B, C;
  for (int i = 1; i <= (int)(q); i++) {
    cin >> b[i] >> c[i];
    B = b[i];
    C = c[i];
    A = x[B];
    x[B] = 0;
    x[C] += A;
    s[i] = s[i - 1] + A * (C - B);
  }
  for (int i = 1; i <= (int)(q); i++) cout << s[i] << endl;
}
