#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> nums;
  for (int i = 0; i < (N); ++i) {
    int tmp;
    cin >> tmp;
    nums[tmp]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    int B, C;
    cin >> B >> C;
    int cnt = nums[B];
    nums[B] = 0;
    nums[C] += cnt;
    long long ans = 0;
    for (auto &s : nums) {
      ans += s.second * s.first;
    }
    cout << ans << endl;
  }
  return 0;
}
