#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, Q, temp, temp2, sum = 0;
  vector<int> nums;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    nums.push_back(temp);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    sum = 0;
    cin >> temp >> temp2;
    for (int j = 0; j < N; j++) {
      if (nums[j] == temp) {
        nums[j] = temp2;
      }
    }
    for (auto& n : nums) {
      sum += n;
    }
    cout << sum << "\n";
  }
  return 0;
}
