#include <bits/stdc++.h>
using namespace std;
int Tong(int a[], int n) {
  int kq = 0;
  for (int i = 0; i < n; ++i) {
    kq += a[i];
  }
  return kq;
}
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int b;
  cin >> b;
  int brr[b][2];
  for (int i = 0; i < b; ++i) {
    for (int j = 0; j < 2; ++j) {
      cin >> brr[i][j];
    }
  }
  for (int i = 0; i < b; ++i) {
    for (int k = 0; k < n; ++k) {
      if (arr[k] == brr[i][0]) arr[k] = brr[i][1];
    }
    cout << Tong(arr, n) << endl;
  }
}
