#include <bits/stdc++.h>
using namespace std;
const long long int mx = 1e5 + 123;
long long int binarySearch(long long int arr[], long long int p,
                           long long int r, long long int num) {
  if (p <= r) {
    long long int mid = (p + r) / 2;
    if (arr[mid] == num) return mid;
    if (arr[mid] > num) return binarySearch(arr, p, mid - 1, num);
    if (arr[mid] < num) return binarySearch(arr, mid + 1, r, num);
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int t, i, j, a, b, x, y, e = 0, ans = 0, sum = 0;
  cin >> a;
  vector<long long int> c(a + 5, 0);
  vector<long long int> d(a);
  for (long long int i = 0; i < a; i++) {
    cin >> d[i];
    sum += d[i];
    c[d[i]]++;
  }
  cin >> b;
  while (b--) {
    cin >> x >> y;
    sum += (y - x) * c[x];
    c[y] += c[x];
    c[x] = 0;
    cout << sum << endl;
  }
}
