#include <bits/stdc++.h>
using namespace std;
multiset<int> nums;
void replace(int b, int c) {
  multiset<int>::iterator it = nums.find(b);
  while (it != nums.end()) {
    nums.erase(it);
    nums.emplace(c);
    it = nums.find(b);
  }
}
long long calcSum() {
  long long sum = 0;
  for (auto it : nums) sum += it;
  return sum;
}
int main() {
  int n, q;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int temp;
    cin >> temp;
    nums.emplace(temp);
  }
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int b, c;
    cin >> b >> c;
    replace(b, c);
    cout << calcSum() << "\n";
  }
}
