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