#include <bits/stdc++.h>
using namespace std;
template <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T POW(T B, T printf) {
  if (printf == 0) return 1;
  if (printf & 1)
    return B * POW(B, printf - 1);
  else
    return POW(B, printf / 2) * POW(B, printf / 2);
}
template <typename T>
T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
long long toLlint(string s) {
  long long sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
template <class T>
string NTS(T Number) {
  stringstream second;
  second << Number;
  return second.str();
}
bool isprime(int w) {
  if (w == 0) return false;
  if (w == 1) return false;
  int sqrtw = int(sqrt((double)w));
  for (int q = 2; q <= sqrtw; q++) {
    if (w % q == 0) return false;
  }
  return true;
}
int main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  };
  long long t;
  cin >> t;
  long long arr[t];
  for (long long i = 0; i < t; i++) cin >> arr[i];
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    for (long long i = 0; i < t; i++) {
      if (arr[i] == b) {
        arr[i] = c;
        sum += arr[i];
      } else
        sum += arr[i];
    }
    cout << sum << "\n";
  }
}
