#include <bits/stdc++.h>
using namespace std;
int s[100005];
int main() {
  memset(s, 0, sizeof(0));
  int n;
  cin >> n;
  int a[n + 1];
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    s[a[i]]++;
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    sum += s[x] * (y - x);
    s[y] += s[x];
    s[x] = 0;
    cout << sum << endl;
  }
}
