#include <bits/stdc++.h>
using namespace std;
long long int binarySearch(long long int arr[], long long int l,
                           long long int r, long long int x) {
  if (r >= l) {
    long long int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
void printtree(long long int arr[], long long int n) {
  for (long long int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
int main(void) {
  long long int n, arr[100010];
  cin >> n;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    for (long long int i = 0; i < n; i++) {
      if (arr[i] == b) {
        arr[i] = c;
        sum = sum + c - b;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
