#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
int main() {
  int N;
  cin >> N;
  map<int, int> mapA;
  int tmp;
  for (int i = 0; i < (N); ++i) {
    cin >> tmp;
    mapA[tmp] += 1;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    int b, c;
    cin >> b >> c;
    mapA[c] += mapA[b];
    mapA[b] = 0;
    long long sum = 0;
    for (const auto& [key, value] : mapA) {
      sum += key * value;
    }
    cout << sum << endl;
  }
  return 0;
}
