#include <bits/stdc++.h>
using namespace std;
int longestIncreasingSubsequenceLenghtDP(int a[], int n) {
  int dp[n], ans = 0;
  for (int k = 0; k < n; k++) {
    dp[k] = 1;
    for (int i = 0; i < k; i++) {
      if (a[i] <= a[k]) {
        dp[k] = max(dp[k], dp[i] + 1);
        ans = max(dp[k], ans);
      }
    }
  }
  return ans;
}
int result[1000] = {0};
int factDP(int n) {
  if (n >= 0) {
    result[0] = 1;
    for (int i = 1; i <= n; ++i) {
      result[i] = i * result[i - 1];
    }
    return result[n];
  }
}
bool checkPrime(int n) {
  if (n < 2) return false;
  for (int x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
vector<int> primeFactors(int n) {
  vector<int> f;
  for (int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      f.push_back(x);
      n /= x;
    }
  }
  if (n > 1) f.push_back(n);
  return f;
}
int binary_Search_Classic(int n, int arr[], int target) {
  int l, r, mid;
  l = 0;
  r = n - 1;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (arr[mid] == target) {
      return mid;
    }
    if (arr[mid] < target) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return -1;
}
int binary_Search_First_Greater(int n, int arr[], int target) {
  int l, r, ans, mid;
  l = 0;
  r = n - 1;
  ans = -1;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (arr[mid] > target) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
int countDistinctCharsString(string s) {
  unordered_map<char, int> m;
  for (int i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  return m.size();
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int s = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
      s += a[i];
    }
    cout << s << "\n";
  }
  return 0;
}
