#include <bits/stdc++.h>
const int INF = 1001001001;
const double PI = 3.14159;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> map(10e5 + 1, 0);
  int a;
  for (int i = 0; i < (n); ++i) {
    cin >> a;
    map[a]++;
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    map[c] += map[b];
    map[b] = 0;
    long long sum = 0;
    for (int j = 0; j < (map.size()); ++j) {
      sum += j * map[j];
    }
    cout << sum << endl;
    ;
  }
}
