#include <bits/stdc++.h>
using namespace std;
int main() {
  int nn, aa, qq;
  long long sum = 0;
  cin >> nn;
  vector<int> tmp(100005);
  for (int i = 0; i < (nn); ++i) {
    cin >> aa;
    tmp[aa]++;
    sum += aa;
  }
  int bb, cc;
  cin >> qq;
  for (int i = 0; i < (qq); ++i) {
    cin >> bb >> cc;
    tmp[cc] += tmp[bb];
    sum += (cc - bb) * tmp[bb];
    tmp[bb] = 0;
    printf("%d\n", sum);
  }
  return 0;
}
