#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> nums(N);
  unordered_map<int64_t, vector<size_t>> map;
  for (int n = 0; n < N; ++n) {
    int64_t num;
    cin >> nums[n];
    map[nums[n]].push_back(n);
  }
  int64_t sum = accumulate(nums.begin(), nums.end(), 0);
  int64_t Q;
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int64_t B, C;
    cin >> B >> C;
    sum += (C - B) * map[B].size();
    cout << sum << endl;
    for (size_t idx : map[B]) {
      map[C].push_back(idx);
      nums[idx] = C;
    }
    map[B].clear();
  }
  return 0;
}
