#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
struct pp {
  int b, c;
} x[100005];
int main() {
  ios::sync_with_stdio(false);
  long long s = 0;
  int n, a[100005], q, vis[100005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vis[a[i]]++;
    s += a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x[i].b >> x[i].c;
  }
  for (int i = 0; i < q; i++) {
    s += vis[x[i].b] * (x[i].c - x[i].b);
    cout << s << "\n";
    vis[x[i].c] += vis[x[i].b];
    vis[x[i].b] = 0;
  }
  return 0;
}
