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