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