#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c, q;
  scanf("%d", &n);
  unordered_map<int, int> cnt;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    cnt[a]++;
    sum += a;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &b, &c);
    int bc = cnt[b];
    long long tot = 1LL * b * bc;
    long long add = 1LL * c * bc;
    sum -= tot;
    sum += add;
    cnt[c] += bc;
    printf("%lld\n", sum);
  }
}
