#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> count(100001);
  int N, s = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count.at(a)++;
    s += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    s -= (B - C) * count[B];
    count[C] += count[B];
    count[B] = 0;
    cout << s << endl;
  }
}
