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