#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, num, q1, q2;
  cin >> n;
  vector<int> nums;
  vector<pair<int, int> > queries;
  while (n--) {
    cin >> num;
    nums.push_back(num);
  }
  cin >> q;
  while (q--) {
    cin >> q1;
    cin >> q2;
    queries.push_back(make_pair(q1, q2));
  }
  int max_sum = accumulate(nums.begin(), nums.end(), 0);
  for (int i = 0; i < queries.size(); i++) {
    for (int j = 0; j < nums.size(); j++) {
      if (queries[i].first == nums[j]) {
        nums[j] = queries[i].second;
        max_sum += queries[i].second - queries[i].first;
      }
    }
    cout << to_string(max_sum) << endl;
  }
  return 0;
}
