#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    cin >> k;
    while (k--) {
      int p, q;
      cin >> p >> q;
      long long sum = 0;
      for (int i = 0; i < n; ++i) {
        if (a[i] == p) a[i] = q;
        sum += a[i];
      }
      cout << sum << endl;
    }
  }
}
