#include <bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  int temp, sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    cnt[temp]++;
    sum += temp;
  }
  cin >> q;
  int b, c;
  for (int i = 0; i < q; ++i) {
    int sum = 0;
    cin >> b >> c;
    int k = cnt[b];
    cnt[b] = 0;
    cnt[c] += k;
    sum = sum + (c - b) * k;
    cout << sum << endl;
  }
  return 0;
}
