#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll ber = 1e18;
const ll M = 1000000000000001;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (n); i++) cin >> a[i];
  int q;
  cin >> q;
  int b[q], c[q];
  for (int j = 0; j < (q); j++) cin >> b[j] >> c[j];
  int ans = 0;
  for (int k = 0; k < q; k++) {
    for (int l = 0; l < (n); l++) {
      if (b[k] == a[l]) {
        a[l] = c[k];
      }
    }
    for (int m = 0; m < (n); m++) {
      ans += a[m];
    }
    cout << ans << endl;
    ans = 0;
  }
}
