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