#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n = 0, q = 0;
  long long int a[100000], b[100000], c[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  long long int s[100001];
  for (int i = 0; i <= n; i++) s[i] = 0;
  for (int i = 0; i < n; i++) s[0] += a[i];
  long long int num[100001];
  for (int i = 0; i <= n; i++) num[i] = 0;
  for (int i = 0; i < n; i++) num[a[i]]++;
  for (int i = 0; i < q; i++) {
    s[i + 1] = s[i] + num[b[i]] * (c[i] - b[i]);
    num[c[i]] += num[b[i]];
    num[b[i]] = 0;
    cout << s[i + 1] << endl;
  }
}
