#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int i, j;
  int ans = 0;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i];
  }
  int q;
  cin >> q;
  int b, c;
  int count;
  int is_plus = 0;
  for (i = 0; i < q; ++i) {
    count = 0;
    cin >> b >> c;
    if (b < c) {
      is_plus = c - b;
    } else {
      is_plus = b - c;
    }
    for (j = 0; j < n; ++j) {
      if (a[j] == b) {
        a[j] = c;
        ++count;
      }
    }
    ans += is_plus * count;
    cout << ans << endl;
  }
  return 0;
}
