#include <bits/stdc++.h>
const double PI = 4 * atan(1);
using namespace std;
int findmin(int a, int b) { return a < b ? a : b; }
int findmax(int a, int b) { return a > b ? a : b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long n, q;
  cin >> n;
  long a[n];
  long long sum = 0;
  unordered_map<long, long> um;
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    um[a[i]]++;
  }
  cin >> q;
  long b, c;
  while (q--) {
    cin >> b >> c;
    long long diff = um[b] * (c - b);
    um[c] += um[b];
    sum += diff;
    cout << sum << "\n";
  }
  cout.flush();
  return 0;
}
