#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll ber = 1e18;
const ll M = 1000000000000001;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (n); i++) cin >> a[i];
  int q;
  cin >> q;
  int b[q], c[q];
  for (int j = 0; j < (q); j++) cin >> b[j] >> c[j];
  int con = 0;
  int ans = 0;
  while (con < q) {
    for (int k = 0; k < (n); k++) {
      if (b[con] == a[k]) {
        a[k] = c[con];
      }
      ans += a[k];
    }
    cout << ans << endl;
    con += 1;
    ans = 0;
  }
}
