#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, arr[100005];
  long long sum = 0;
  map<int, int> mps;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    mps[arr[i]]++;
    sum += arr[i];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);
    if (!mps[b]) {
      printf("%lld\n", sum);
      continue;
    }
    int x = mps[b];
    sum -= (long long)(x * b);
    sum += (long long)(x * c);
    mps[c] += x;
    mps[b] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
