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