#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
  int n;
  scanf("%d", &n);
  int freq[100005];
  memset(freq, 0, sizeof(freq));
  int arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    freq[arr[i]]++;
    sum += arr[i];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    long long temp1 = a * freq[a];
    long long temp2 = b * freq[a];
    freq[b] += freq[a];
    freq[a] = 0;
    sum = sum - temp1 + temp2;
    printf("%lld\n", sum);
  }
  return;
}
int main() {
  solve();
  return 0;
}
