#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void testcase() {
  int n;
  cin >> n;
  int a[n], sum = 0;
  unordered_map<int, int> freq;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
    freq[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    freq[c] += freq[b];
    sum = sum + freq[b] * (c - b);
    freq[b] = 0;
    cout << sum << '\n';
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    testcase();
  }
  return 0;
}
