#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  scanf("%d", &n);
  int a[n];
  long long sum = 0;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    m[a[i]]++;
  }
  long long t, b, c;
  cin >> t;
  while (t--) {
    cin >> b >> c;
    long long timesb = m[b];
    long long timesc = m[c];
    sum -= (b * timesb);
    m[c] += timesb;
    sum += (timesb * c);
    m[b] = 0;
    cout << sum << "\n";
  }
}
