#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int q;
  cin >> q;
  for (int test = 0; test < q; test++) {
    int a, b;
    cin >> a >> b;
    int c = 0, diff = b - a;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) {
        c++;
        arr[i] = b;
      }
    }
    sum = sum + (diff * c);
    cout << sum << "\n";
  }
}
