#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int val;
  cin >> N;
  vector<int> ival;
  for (int i = 0; i < N; i++) {
    cin >> val;
    ival.push_back(val);
  }
  int Q, b, c;
  cin >> Q;
  vector<int>::iterator it;
  for (int i = 0; i < Q; i++) {
    cin >> b;
    cin >> c;
    it = find(ival.begin(), ival.end(), b);
    while (it != ival.end()) {
      *it = c;
      it = find(ival.begin(), ival.end(), b);
    }
    cout << accumulate(ival.begin(), ival.end(), 0) << '\n';
  }
}
