#include <bits/stdc++.h>
using namespace std;
int res[10005] = {0};
int main() {
  int N, d = 0;
  long long sum = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &d);
    res[d]++;
    sum += d;
  }
  int Q;
  scanf("%d", &Q);
  int y = 0, x = 0;
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &y, &x);
    sum += (x - y) * res[y];
    res[x] += res[y];
    res[y] = 0;
    cout << sum << endl;
  }
  return 0;
}
