#include <bits/stdc++.h>
using namespace std;
int MAP[100001] = {-1};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> freq;
  int tmp;
  for (int i = 0; i < (int)(N); ++i) {
    cin >> tmp;
    freq[tmp]++;
  }
  int Q;
  cin >> Q;
  int B, C;
  for (int i = 0; i < (int)(Q); ++i) {
    cin >> B >> C;
    freq[C] += freq[B];
    freq[B] = 0;
    uint64_t ret = 0;
    for (auto itr : freq) {
      ret += itr.first * itr.second;
    }
    cout << ret << endl;
  }
  return 0;
}
