#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const double eps = 1e-10;
long long cnt[N], a[N];
int main() {
  int n;
  memset(cnt, 0, sizeof(cnt));
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ans += a[i];
    cnt[a[i]]++;
  }
  int q;
  scanf("%d", &q);
  long long x, y;
  for (int i = 1; i <= q; i++) {
    scanf("%lld%lld", &x, &y);
    cnt[y] += cnt[x];
    ans += (y - x) * cnt[x];
    printf("%lld\n", ans);
  }
  return 0;
}
