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