#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007;
const int MAX_N = 100000;
int A[MAX_N];
long long sum = 0;
int cnt[MAX_N + 1];
void init(int N) {
  for (int i = 0; i < N; ++i) sum += A[i], ++cnt[A[i]];
}
void update(int B, int C) {
  long long t = cnt[B];
  sum -= t * B;
  sum += t * C;
  cnt[B] = 0;
  cnt[C] += t;
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  init(N);
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    update(B, C);
    int ans = sum;
    printf("%d\n", ans);
  }
}
