#include <bits/stdc++.h>
using namespace std;
const int max_S = 1e5 + 10;
int s[max_S];
int main() {
  for (int i = 0; i < max_S; i++) {
    s[i] = 0;
  }
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < n; i++) {
    s[a[i]]++;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  for (int i = 0; i < q; i++) {
    sum += s[b[i]] * (c[i] - b[i]);
    s[c[i]] += s[b[i]];
    s[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
