#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long int, long long int> numList;
  long long int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    long long int num;
    cin >> num;
    sum += num;
    if (numList.count(num) == 0) {
      numList.insert(make_pair(num, 1));
    } else {
      numList[num]++;
    }
  }
  long long int Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    long long int b, c;
    cin >> b >> c;
    long long int x;
    if (numList.count(b) == 0) {
      continue;
    } else {
      x = numList[b];
      sum = sum - x * b + x * c;
      numList.erase(b);
      numList.insert(make_pair(c, x));
    }
    cout << sum << endl;
  }
  return 0;
}
