#include <bits/stdc++.h>
using namespace std;
const int mxn = (int)10e5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long freq[mxn + 1], sum = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    freq[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    sum = sum - freq[b] * b + freq[b] * c;
    freq[b] = 0;
    freq[c] += b;
    cout << sum << "\n";
  }
}
