#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[500000];
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  while (q--) {
    int c, b, sum = 0;
    cin >> c >> b;
    int old_val = c, new_val = b;
    replace(a, a + n, old_val, new_val);
    cout << accumulate(a, a + n, sum) << endl;
  }
}
