#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<int, int> count;
  long long ans = 0;
  for (int i = 0; i <= 100000; i++) count[i] = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count[a] += 1;
    ans += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    ans = ans - B * count[B] + C * count[B];
    count[C] += count[B];
    count[B] = 0;
    cout << ans << endl;
  }
  return 0;
}
