#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> num(1e5, 0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    num[a[i]] += 1;
  }
  cin >> q;
  std::vector<int> b(q);
  std::vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    sum = sum + num[b[i]] * (c[i] - b[i]);
    num[c[i]] += num[b[i]];
    num[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
