#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, q, b, c;
  cin >> n;
  long long sum = 0;
  map<int, int> m;
  int a[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i], sum += a[i], m[a[i]]++;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    int x = m[b];
    sum = sum - (b * x);
    sum = sum + (c * x);
    m[b] = 0;
    m[c] += x;
    cout << sum << '\n';
  }
}
