#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
void solve() {
  long long n, q;
  cin >> n;
  long long sum = 0;
  vector<int> arr(100008, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    arr[x]++;
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long x, y;
    cin >> x >> y;
    if (arr[x] == 0) {
      cout << sum << endl;
      continue;
    }
    sum -= (arr[x] * x);
    long long t = 1;
    if (arr[y]) {
      t = arr[y];
      arr[y]++;
    } else {
      arr[y] = arr[x];
      t = arr[y];
    }
    arr[x] = 0;
    sum += (t * y);
    cout << sum << endl;
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int t;
  solve();
  return 0;
}
