#include <bits/stdc++.h>
using namespace std;
inline int Int() {
  int x;
  cin >> x;
  return x;
}
inline long long Long() {
  long long x;
  cin >> x;
  return x;
}
inline float Float() {
  float x;
  cin >> x;
  return x;
}
inline double Double() {
  double x;
  cin >> x;
  return x;
}
inline void Yes() { cout << "Yes" << endl; }
inline void No() { cout << "No" << endl; }
inline void YES() { cout << "YES" << endl; }
inline void NO() { cout << "NO" << endl; }
const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
int main() {
  long long N, Q, i, j, sum;
  cin >> N;
  long long A[N];
  for (i = 0; i < N; i++) cin >> A[i];
  cin >> Q;
  long long B[Q], C[Q];
  for (i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    sum = 0;
    for (j = 0; j < N; j++) {
      if (A[j] == B[i]) A[j] = C[i];
      sum += A[j];
    }
    cout << sum << endl;
  }
  return 0;
}
