#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[100001] = {}, sum = 0;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    sum += c;
    a[c]++;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int t;
  solve();
  return 0;
}
