#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
const long long MAX = 100001;
void solve() {
  int n;
  cin >> n;
  vector<int> vec(MAX, 0);
  long long sm = 0;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    vec[p]++;
    sm += p;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sm -= vec[b] * b;
    sm += vec[b] * c;
    vec[c] += vec[b];
    vec[b] = 0;
    cout << sm << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
