#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int npr(int n, int r) {
  r = n - r;
  int sum = 1;
  int i;
  for (i = n; i >= r + 1; i--) sum *= i;
  return sum;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int digsum(int n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}
bool isPrime(int x) {
  if (x == 1) return 0;
  if (x == 2) return 1;
  if (x % 2 == 0) return 0;
  for (int i = 3; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
signed main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
  long long int q;
  cin >> q;
  for (int(i) = 0; (i) < (q); (i)++) {
    long long int sum = 0;
    long long int b, c;
    cin >> b >> c;
    for (int(j) = 0; (j) < (n); (j)++) {
      if (a[j] == b) {
        a[j] = c;
      }
      sum += a[j];
    }
    cout << sum << endl;
  }
  return 0;
}
