#include <bits/stdc++.h>
using namespace std;
long long test_cases;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  test_cases = 1;
  long long n;
  long long a[100123], freq[100123];
  long long q, ansi = 0;
  while (test_cases > 0) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      ansi += a[i];
      freq[a[i]]++;
    }
    cin >> q;
    long long b, c;
    while (q > 0) {
      cin >> b >> c;
      if (c > b) {
        ansi += (c - b) * freq[b];
        freq[c] += freq[b];
        freq[b] = 0;
      }
      if (c < b) {
        ansi -= (b - c) * freq[b];
        freq[c] += freq[b];
        freq[b] = 0;
      }
      cout << ansi << endl;
      q--;
    }
    test_cases--;
  }
  return 0;
}
