#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  vector<int> v;
  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];
    for (int k = 0; k < n; k++) {
      if (b[j] == a[k]) a[k] = c[j];
    }
    for (int l = 0; l < n; l++) cnt += a[l];
    v.push_back(cnt);
    cnt = 0;
  }
  for (int lol = 0; lol < v.size(); lol++) cout << v[lol] << endl;
}
