#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000];
int q;
int b[100000];
int c[100000];
int bin[100000];
void solve() {
  int sum = accumulate(a, a + n, 0);
  for (int i = 0; i < q; i++) {
    sum += (c[i] - b[i]) * bin[b[i]];
    bin[c[i]] += bin[b[i]];
    bin[b[i]] = 0;
    printf("%d\n", sum);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    bin[a[i]]++;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &b[i]);
    scanf("%d", &c[i]);
  }
  solve();
}
