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