#include <bits/stdc++.h>
using namespace std;
unsigned long long int dp[3][100010];
unsigned long long int v[100010];
int main() {
  int n, aux;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &aux);
    v[i] = aux;
  }
  dp[1][0] = 0;
  for (int i = 0; i < n; i++) {
    dp[1][i + 1] = dp[1][i] + v[i];
  }
  sort(v, v + n);
  dp[2][0] = 0;
  for (int i = 0; i < n; i++) {
    dp[2][i + 1] = dp[2][i] + v[i];
  }
  char saida[10] = "%I64u\n";
  int m, l, r, type;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &type);
    scanf("%d", &l);
    scanf("%d", &r);
    printf(saida, dp[type][r] - dp[type][l - 1]);
  }
}
