#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;
vector<vector<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();
    if (an[a].size() == 0)
      an[a].push_back(1);
    else
      an[a][0] += 1;
    ans += a;
  }
  q = read();
  while (q--) {
    b = read();
    c = read();
    ans -= an[b][0] * b;
    ans += an[b][0] * c;
    cout << ans << endl;
    if (an[c].size() == 0)
      an[c].push_back(an[b][0]);
    else
      an[c][0] += an[b][0];
    an[b].clear();
  }
  return 0;
}
