#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j, arra[100000], b[100000], c[100000], k, sum = 0;
  string s;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arra[i];
  }
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> b[i] >> c[i];
  }
  for (i = 0; i < t; i++) {
    for (j = 0; j < n; j++) {
      if (arra[j] == b[i]) arra[j] = c[i];
    }
    cout << accumulate(arra, arra + n, sum) << endl;
  }
  return 0;
}
