#include <bits/stdc++.h>
using namespace std;
long long res = 0;
const int N = 1e5 + 10;
int h[N], n, Q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    h[x]++;
    res += x;
  }
  scanf("%d", &Q);
  while (Q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int cnt = h[a];
    res -= 1ll * cnt * a;
    res += 1ll * cnt * b;
    h[b] += cnt;
    printf("%lld\n", res);
  }
  return 0;
}
