#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<long long> v1(t);
  for (int i = 0; i < t; i++) cin >> v1[i];
  vector<long long> v2 = v1;
  sort(v2.begin(), v2.end());
  for (int i = 1; i < t; i++) {
    v1[i] += v1[i - 1];
    v2[i] += v2[i - 1];
  }
  int tt, type, st, ed;
  cin >> tt;
  while (tt--) {
    cin >> type;
    cin >> st;
    cin >> ed;
    if (st == 1) {
      if (type == 1)
        cout << v1[ed - 1] << endl;
      else
        cout << v2[ed - 1] << endl;
      continue;
    }
    if (type == 1)
      cout << v1[ed - 1] - v1[st - 2];
    else
      cout << v2[ed - 1] - v2[st - 2];
    cout << endl;
  }
  return 0;
}
