#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, sum = 0;
  cin >> n;
  long long int arr[n + 1], cnt[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum = sum + arr[i];
  }
  long long int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    long long int b, c, cnt = 0;
    cin >> b >> c;
    for (long long int i = 0; i < n; i++) {
      if (b == arr[i]) {
        cnt++;
        arr[i] = c;
      }
    }
    if (b <= c)
      sum = sum + (c - b) * cnt;
    else
      sum = sum - (b - c) * cnt;
    cout << sum << endl;
  }
  return 0;
}
