#include <bits/stdc++.h>
using namespace std;
int n, a[100005], b[100005], c[100005], s[100005], q;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> 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]) {
        a[j] = c[i];
      }
      s[i] += a[j];
    }
    cout << s[i] << endl;
  }
  return 0;
}
