#include <bits/stdc++.h>
using namespace std;
int sum(int arr[], int n) {
  int sum = 0;
  for (int i = 0; i < n; i++) sum = sum + arr[i];
  return sum;
}
void per(int arr[], int n, int x, int y) {
  for (int i = 0; i < n; i++) {
    if (arr[i] == x)
      arr[i] = y;
    else
      continue;
  }
}
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  int a, b;
  int ans;
  while (q--) {
    cin >> a >> b;
    per(arr, n, a, b);
    ans = sum(arr, n);
    cout << ans << endl;
  }
}
