#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long N;
  cin >> N;
  vector<long> table;
  for (long i = 0; i < N; i++) {
    long tmp = 0;
    cin >> tmp;
    table.push_back(tmp);
  }
  long Q;
  cin >> Q;
  for (long i = 0; i < Q; i++) {
    long B, C;
    cin >> B >> C;
    long sum = 0;
    for (long i = 0; i < table.size(); i++) {
      if (table[i] == B) {
        table[i] = C;
      }
      sum += table[i];
    }
    cout << sum << endl;
  }
}
