#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double PI = 3.14159265358979;
const long long MAX = 0;
int main() {
  long long N, sum = 0;
  cin >> N;
  long long a[100001];
  for (int i = 0; i < N; i++) {
    long long n;
    cin >> n;
    a[n]++;
    sum += n;
  }
  long long Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long b, c;
    cin >> b >> c;
    long long B = a[b];
    a[b] = 0;
    a[c] += B;
    sum += B * (c - b);
    cout << sum << endl;
  }
}
