#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  for (int j = 0; j < q; j++) {
    int sum = 0;
    int bi, ci;
    cin >> bi >> ci;
    for (int k = 0; k < n; k++) {
      if (bi == arr[k]) {
        arr[k] = ci;
      }
      sum = sum + arr[k];
    }
    cout << sum << endl;
  }
}
