#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  long long x = 0;
  for (int i = 0; i < n; i++) cin >> a[i], x += a[i];
  int q;
  cin >> q;
  int b[q], c[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 (a[j] == b[i]) {
        x = x - a[j] + c[i];
        a[j] = c[i];
      }
    }
    cout << x << endl;
  }
}
