""" Left Addition Machine 想定TLE解法v1.1 愚直に解く。 O(N^2Q) maxを求めているのにmodを計算してしまっていたのを修正 """ import sys from sys import stdin def solve(arr): #愚直に解く while len(arr) > 1: maxind = 0 for i in range(len(arr)): if arr[maxind] < arr[i]: maxind = i for j in range(maxind): arr[j] += arr[maxind] del arr[maxind] return arr[0] % mod mod = 998244353 #入力を受け取る N,Q = map(int,stdin.readline().split()) A = list(map(int,stdin.readline().split())) LR = [] for i in range(Q): L,R = map(int,stdin.readline().split()) LR.append( (L,R) ) #制約チェック assert 1 <= N <= 2*(10**5) assert 1 <= Q <= 2*(10**5) assert len(A) == N assert len(LR) == Q for i in range(N): assert 0 <= A[i] < mod for i in range(Q): L,R = LR[i] assert 1 <= L <= R <= N ANS = [] for loop in range(Q): l,r = LR[loop] l -= 1 r -= 1 ANS.append(solve(A[l:r+1])) print ("\n".join(map(str,ANS)))