#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> hist;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    hist[A]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    hist[C] += hist[B];
    hist[B] = 0;
    long long S = 0;
    for (auto h : hist) {
      S += h.first * h.second;
    }
    cout << S << endl;
  }
  return 0;
}
