#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  long long S = 0;
  map<int, int> v;
  cin >> N;
  for (int i = 0; i < (int)(N); i++) {
    int n;
    cin >> n;
    v[n]++;
  }
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    S = 0;
    int b, c;
    cin >> b >> c;
    v[c] += v[b];
    v[b] = 0;
    for (auto p : v) {
      S += (p.first * p.second);
    }
    cout << S << endl;
  }
}
