#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
unordered_map<int, int> cnt;
int main() {
  int n;
  unsigned long long sum = 0ll;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
    ++cnt[a[i]];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    sum = sum - x * cnt[x] + y * cnt[x];
    cnt[y] += cnt[x];
    cnt[x] = 0;
    printf("%llu\n", sum);
  }
}
