#include <bits/stdc++.h>
using namespace std;
void print(const unordered_map<int, int> &m) {
  long long sum = 0;
  for (auto p : m) {
    sum += p.first * p.second;
  }
  cout << sum << endl;
}
int main() {
  int N, M;
  cin >> N;
  unordered_map<int, int> m;
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    m[n]++;
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      m[c] += m[b];
    }
    m.erase(b);
    print(m);
  }
  return 0;
}
