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