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