#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int N;
int a[100000];
int p[100001] = {0};
int Q;
vector<int> ans;
int main() {
  cin >> N;
  for (int i = 0; i < (int)(N); ++i) {
    cin >> a[i];
    p[a[i]] += 1;
  }
  int sum = 0;
  for (int i = 0; i < (int)(N); ++i) {
    sum += a[i];
  }
  cin >> Q;
  for (int i = 0; i < (int)(Q); ++i) {
    int b, c;
    cin >> b >> c;
    int s = c - b;
    sum += s * p[b];
    ans.push_back(sum);
    p[c] += p[b];
    p[b] = 0;
  }
  for (int i = 0; i < (int)(ans.size()); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
