Sereja and Commands

My following code is failing. I tried very much but couldn’t find the reason. Please help. Thanks in advance.

import java.io.;
import java.math.
;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

class SEACO {

public static int mod = 1000000007;
static FasterScanner in = new FasterScanner();
static PrintWriter out = new PrintWriter(System.out);
static class Query
{
	int type;
	int l;
	int r;
	Query(int type,int l,int r)
	{
		this.type=type;
		this.l=l;
		this.r=r;
	}
	
}
public static void main(String[] args) {

	int testcases=in.nextInt();
	while(testcases-->0)
	{
		int n=in.nextInt();
		int m=in.nextInt();
		long[] answerarray=new long[n+2];
		long[] temparray=new long[n+2];
		long[] count=new long[m+2];
		long[] differencecount=new long[m+1];
		Query[] query=new Query[m+1];
		for(int i=1;i<=m;i++)
		{
			query[i]=new Query(in.nextInt(), in.nextInt(), in.nextInt());
		}
		count[m+1]=1;
		for(int i=m;i>=1;i--)
		{
			count[i]=count[i+1]+differencecount[i];
			if(query[i].type==2)
			{
				differencecount[query[i].r]+=count[i];
				differencecount[query[i].l-1]-=count[i];
				//differencecount[query[i].r]%=mod;
				//differencecount[query[i].l-1]%=mod;
			}
			/*else if(query[i].type==1)
			{
				temparray[query[i].l]+=count[i];
				temparray[query[i].r+1]-=count[i];
				temparray[query[i].l]%mod;
				temparray[query[i].r+1]%=mod;
			}*/
		}
		for(int i=1;i<=m;i++)
		{
			if(query[i].type==1)
			{
				answerarray[query[i].l]+=count[i];
				answerarray[query[i].r+1]=(answerarray[query[i].r+1]-count[i]);
				//answerarray[query[i].l]%=mod;
				//answerarray[query[i].r+1]%=mod;
			}
		}
		for(int i=1;i<=n;i++)
		{
			answerarray[i]+=answerarray[i-1];
			answerarray[i]%=mod;
		}
		for(int i=1;i<=n;i++)
		{
			out.print(answerarray[i]+" ");
		}
		out.println();
	}
	out.close();

}

public static long pow(long x, long n, long mod) {
	long res = 1;
	for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
		if ((n & 1) != 0) {
			res = (res * p % mod);
		}
	}
	return res;
}

public static long gcd(long n1, long n2) {
	long r;
	while (n2 != 0) {
		r = n1 % n2;
		n1 = n2;
		n2 = r;
	}
	return n1;
}

static class FasterScanner {
	private byte[] buf = new byte[1024];
	private int curChar;
	private int snumChars;

	public int read() {
		if (snumChars == -1)
			throw new InputMismatchException();
		if (curChar >= snumChars) {
			curChar = 0;
			try {
				snumChars = System.in.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (snumChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public String nextString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	public long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}
}

}