#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long sum = 0;
  long long ar[n];
  for (long long i = 0; i < n; i++) {
    cin >> ar[i];
    sum = sum + ar[i];
  }
  long long q;
  cin >> q;
  long long a, b;
  while (q--) {
    cin >> a >> b;
    long long c = count(ar, ar + n, a);
    replace(ar, ar + n, a, b);
    sum = sum + (c * (b - a));
    cout << sum << '\n';
  }
}
