#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 m;
  cin >> m;
  while (m--) {
    int j, k, s = 0;
    cin >> j >> k;
    for (int i = 0; i < n; i++) {
      if (a[i] == j) a[i] = k;
      s += a[i];
    }
    cout << s << endl;
  }
  return 0;
}
