#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (m.find(a[i]) == m.end()) {
      m[a[i]] = 1;
    } else {
      m[a[i]]++;
    }
    sum += a[i];
  }
  int q;
  cin >> q;
  for (; q--;) {
    int b, c, x;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      int x = m[b];
      if (m.find(c) != m.end()) {
        m[c] += m[b];
      } else {
        m[c] = m[b];
      }
      m[b] = 0;
      sum += x * (c - b);
    }
    cout << sum << endl;
  }
}
