#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int freq[100001];
void findAns() {
  memset(freq, 0, sizeof(freq));
  int n;
  cin >> n;
  int x;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    freq[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  int a, b;
  while (q--) {
    cin >> a >> b;
    sum = sum - a * freq[a] + b * (freq[a]);
    freq[b] += freq[a];
    freq[a] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  findAns();
}
