#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 100005;
int cmp(int a, int b) { return a > b; }
int gcd(int x, int y) {
  while (y ^= x ^= y ^= x %= y)
    ;
  return x;
}
int a[100005];
int x, y;
int main() {
  int n, k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    int s = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == x) {
        a[j] = y;
      }
      s += a[j];
    }
    cout << s << endl;
  }
  return 0;
}
