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