#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int main() {
  int tt = 0, i, j, n, q;
  cin >> n;
  int a[n + 1], d[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    tt += a[i];
  }
  cin >> q;
  int b[q + 1], c[q + 1];
  for (i = 1; i <= q; i++) {
    cin >> b[i] >> c[i];
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (a[i] == j) {
        d[j]++;
      }
    }
  }
  for (i = 1; i <= q; i++) {
    for (j = 1; j <= q; j++) {
      if (a[i] == b[j]) {
        tt += (c[j] - a[i]) * d[i];
        cout << tt << endl;
      }
    }
  }
  return 0;
}
