#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return x * f;
}
const int N = 1e5 + 5;
multiset<int> s;
vector<multiset<int> > an(N);
long long ans = 0;
int n, q, a, b, c;
int main() {
  n = read();
  for (int i = (1); i <= (n); ++i) {
    a = read();
    an[a].insert(a);
    ans += a;
  }
  q = read();
  while (q--) {
    b = read();
    c = read();
    ans -= (long long)b * an[b].size();
    ans += (long long)c * an[b].size();
    cout << ans << endl;
    int len = an[b].size();
    an[b].clear();
    for (int i = 1; i <= len; ++i) an[c].insert(c);
  }
  return 0;
}
