#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c, sum;
  cin >> n;
  vector<int> value;
  sum = 0;
  for (int i = 0; i < n; i++) {
    int a1;
    cin >> a1;
    sum = sum + a1;
    value.push_back(a1);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    for (int j = 0; j < n; j++) {
      if (value[j] == b) {
        value[j] = c;
        sum = sum - b + c;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
