#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  map<int, int> cnt;
  int sum = 0;
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    cnt[A[i]]++;
    sum += A[i];
  }
  cin >> Q;
  for (int i = 0; i < (Q); i++) {
    int B, C;
    cin >> B >> C;
    int cntA = cnt[B];
    int sub = C - B;
    sum += cntA * sub;
    cnt[C] += cnt[B];
    cnt[B] = 0;
    cout << sum << endl;
  }
  return 0;
}
