#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
string s, s1;
long long n, m, k, cnt;
int main() {
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, cnt = 0;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) arr[i] = b;
      cnt += arr[i];
    }
    cout << cnt << endl;
    cnt = 0;
  }
}
