#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  cout << endl;
  int q;
  cin >> q;
  std::vector<int>::iterator it;
  it = v.begin();
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    while (it != v.end()) {
      it = std::find(v.begin(), v.end(), b);
      *it = c;
    }
    it = v.begin();
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}
