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