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