#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e8;
const double pi = 3.1415926535897;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
struct edge {
  int from, to, w;
  edge() {}
  edge(int x, int y, int we) : from(x), to(y), w(we) {}
  bool operator<(const edge &rhs) const { return w > rhs.w; }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int cnt[(int)1e5 + 5] = {};
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum += cnt[b] * c;
    cout << sum << "\n";
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
}
