#include <bits/stdc++.h>
using namespace std;
long long arraySum(int a[], int n) {
  int initial_sum = 0;
  return accumulate(a, a + n, initial_sum);
}
int main() {
  int n, k, temp;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  while (q > 0) {
    cin >> k;
    cin >> temp;
    for (int i = 0; i < n; i++) {
      if (arr[i] == k) {
        arr[i] = temp;
      }
    }
    long long sum = arraySum(arr, n);
    cout << sum << endl;
    q--;
  }
  return 0;
}
