#include <bits/stdc++.h>
using namespace std;
int absolute(int a);
int binarySearch(int *Arr, int size, int target);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  long long sum = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int c, d, flag = 0;
    cin >> c >> d;
    if (c != d) {
      for (int i = 0; i < n; i++) {
        if (a[i] == c) {
          a[i] = d;
          sum += d - c;
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
int binarySearch(int *Arr, int size, int target) {
  int left = 0;
  int right = size - 1;
  while (left <= right) {
    int mid = left + (right - left) / 2;
    if (Arr[mid] == target)
      return mid;
    else if (Arr[mid] > target)
      right = mid - 1;
    else
      left = mid + 1;
  }
  return -1;
}
int absolute(int a) {
  if (a < 0) return -a;
  return a;
}
