#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  int a[x];
  for (int i = 0; i < x; i++) {
    cin >> a[i];
  }
  int t;
  cin >> t;
  while (t > 0) {
    int z, b;
    cin >> z >> b;
    for (int i = 0; i < x; i++) {
      if (a[i] == z) {
        a[i] = b;
      }
    }
    int s = 0;
    for (int i = 0; i < x; i++) {
      s = s + a[i];
    }
    cout << s << endl;
  }
  t--;
}
