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