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