#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
  int m;
  sort(b, b + n);
  cin >> m;
  for (int i = 1; i < n; i++) a[i] += a[i - 1], b[i] += b[i - 1];
  while (m--) {
    long long ans = 0;
    long long w, x, y;
    cin >> w >> x >> y;
    if (x == 1) {
      if (w == 1) ans = a[y - 1];
      if (w == 2) ans = b[y - 1];
    } else {
      if (w == 1) ans = a[y - 1] - a[x - 2];
      if (w == 2) ans = b[y - 1] - b[x - 2];
    }
    cout << ans << endl;
  }
  return 0;
}
