#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int l;
  cin >> l;
  vector<int> le(l);
  for (int &i : le) {
    cin >> i;
  }
  int query_time;
  cin >> query_time;
  for (int i = 0; i < query_time; ++i) {
    int start, end;
    cin >> start >> end;
    int sum = 0;
    for (int &j : le) {
      if (j == start) {
        j = end;
      }
      sum += j;
    }
    cout << sum << endl;
  }
  return 0;
}
