#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
const int INF = 0x7fffffff;
const int inf = 100000;
const double EPS = 1e-6;
const unsigned long long base = 123;
const long long mod = 1e9 + 7;
const double pi = 4 * atan(1.0);
map<int, int> vis;
int sum = 0;
int a[MAX_N];
int main() {
  int n;
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    vis[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    vis[c] += vis[b];
    sum += (c - b) * vis[b];
    vis[b] = 0;
    cout << sum << endl;
  }
}
