#include <bits/stdc++.h>
using namespace std;
int num[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q, i;
  long long sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> num[i];
    sum += num[i];
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int rel = c - b, ctr = 0;
    for (i = 0; i < n; i++) {
      if (num[i] == b) {
        num[i] = c;
        ctr++;
      }
    }
    sum += rel * ctr;
    cout << sum << '\n';
  }
  return 0;
}
