#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<int> p;
  int n;
  int nums[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  int q;
  cin >> q;
  unsigned int sum = 0;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum = 0;
    for (int j = 0; j < n; j++) {
      if (nums[j] == b) {
        nums[j] = c;
      }
      sum += nums[j];
    }
    cout << sum << endl;
  }
}
