#include <bits/stdc++.h>
using namespace std;
void print_array(int array[], int amount) {
  for (int i = 0; i < amount; i++) {
    cout << array[i] << endl;
  }
  cout << endl;
}
void input_elements(int array[], int amount) {
  for (int i = 0; i < amount; i++) {
    cin >> array[i];
  }
}
void input_elements_2array(int array[], int brray[], int amount) {
  for (int i = 0; i < amount; i++) {
    cin >> array[i];
    cin >> brray[i];
  }
}
void check(int array[], int n, int check_num, int replace_num) {
  for (int i = 0; i < n; i++) {
    if (array[i] == check_num) {
      array[i] = replace_num;
    }
  }
}
int sum(int array[], int amount) {
  int t = 0;
  for (int i = 0; i < amount; i++) {
    t = t + array[i];
  }
  return t;
}
int main() {
  int n0, q0;
  cin >> n0;
  const int n = n0;
  int a[n];
  input_elements(a, n);
  cin >> q0;
  const int q = q0;
  int b[q], c[q];
  input_elements_2array(b, c, q);
  for (int i = 0; i < q; i++) {
    check(a, n, b[i], c[i]);
    cout << sum(a, n) << endl;
  }
  return 0;
}
