#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

long long N;
long long a[100000];
long long p[100001] = {0};
long long Q;
vector<long long> ans;

int8_t main() {
  cin >> N;
  rep(i, N) {
    cin >> a[i];
    p[a[i]] += 1;
  }

  long long sum = 0;
  rep(i, N) {
    sum += a[i];
  }
  cin >> Q;
  rep(i, Q) {
    long long b, c;
    cin >> b >> c;
    long long s = c - b;
    sum += s * p[b];
    ans.push_back(sum);
    p[c] += p[b];
    p[b] = 0;
  }

  rep(i, ans.size()) {
    cout << ans[i] << endl;
  }

  return 0;
}