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