#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  long long n;
  cin >> n;
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end());
  vector<int> l(100001, 0);
  int c = 0;
  int t;
  for (int i = 0; i < n; i++) {
    c = 1;
    t = v[i];
    while (t == v[i + 1]) {
      c += 1;
      i += 1;
    }
    l[t] = c;
  }
  int q;
  cin >> q;
  int x, y;
  long long res = 0;
  for (int i = 1; i < 100001; i++) {
    res += i * l[i];
  }
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    res += (l[y] * y - l[x] * x);
    cout << res << endl;
    l[y] += l[x];
    l[x] = 0;
  }
}
