#include <bits/stdc++.h>
using namespace std;
int solve();
int main() {
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
int solve() {
  long long int n, m, query, l, r, ans, input;
  cin >> n;
  long long int pre_arr[n + 1], sorted_pre_arr[n + 1];
  pre_arr[0] = 0;
  sorted_pre_arr[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> input;
    pre_arr[i] = input;
    sorted_pre_arr[i] = input;
  }
  sort(sorted_pre_arr, sorted_pre_arr + n + 1);
  for (int i = 1; i <= n; ++i) {
    pre_arr[i] += pre_arr[i - 1];
    sorted_pre_arr[i] += sorted_pre_arr[i - 1];
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> query >> l >> r;
    if (query == 1)
      ans = pre_arr[r] - pre_arr[l - 1];
    else
      ans = sorted_pre_arr[r] - sorted_pre_arr[l - 1];
    cout << ans << "\n";
  }
  return 0;
}
