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