#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const long long MOD = 1e9 + 7;
const long long MAX_N = 1e5 + 1;
long long C[MAX_N];
int main() {
  long long i, j, k;
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (auto &e : A) {
    cin >> e;
    C[e]++;
  }
  long long s = accumulate(A.begin(), A.end(), 0);
  long long Q;
  cin >> Q;
  for (i = 0; i < Q; i++) {
    long long b, c;
    cin >> b >> c;
    long long bcount = C[b];
    C[b] = 0;
    C[c] += bcount;
    s += bcount * (c - b);
    cout << s << endl;
  }
  return 0;
}
