#include <bits/stdc++.h>
using namespace std;
typedef struct data_info {
  long long val;
  long long count;
} data_info;
int main(void) {
  long long N, Q;
  cin >> N;
  long long sum = 0;
  vector<data_info> data;
  for (int i = 0; i < N; i++) {
    long long val;
    cin >> val;
    vector<data_info>::iterator it = std::find_if(
        data.begin(), data.end(),
        [val](const data_info &other) { return other.val == val; });
    if (it == data.end()) {
      data.emplace_back(data_info{val, 1});
    } else {
      it->count += 1;
    }
    sum += val;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long B, C;
    cin >> B;
    cin >> C;
    vector<data_info>::iterator itB =
        std::find_if(data.begin(), data.end(),
                     [B](const data_info &other) { return other.val == B; });
    vector<data_info>::iterator itC =
        std::find_if(data.begin(), data.end(),
                     [C](const data_info &other) { return other.val == C; });
    if (itB != data.end()) {
      long long d = (C - B) * itB->count;
      if (itC == data.end()) {
        itB->val = C;
      } else {
        itC->count += itB->count;
        data.erase(itB);
      }
      sum += d;
    }
    cout << sum << endl;
  }
}
