1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 using namespace std;
5
6 #define Mod 1000000007
7 typedef long long LL;
8 const int maxn=100010;
9 LL a[maxn];
10
11 struct node
12 {
13 LL mat[2][2];
14 void set(int x)//初始化矩阵
15 {
16 mat[0][0]=1;
17 mat[0][1]=a[x]%Mod;
18 mat[1][0]=1;
19 mat[1][1]=0;
20
21 }
22 };
23
24 struct IntervalTree
25 {
26 int left,right;
27 node matrix;
28 }f[maxn<<2];
29
30
31 node mat_mul_mod(node A,node B)//矩阵乘法取模
32 {
33 node ret;
34 ret.mat[0][0]=(A.mat[0][0]*B.mat[0][0]%Mod+A.mat[0][1]*B.mat[1][0]%Mod)%Mod;
35 ret.mat[0][1]=(A.mat[0][0]*B.mat[0][1]%Mod+A.mat[0][1]*B.mat[1][1]%Mod)%Mod;
36 ret.mat[1][0]=(A.mat[1][0]*B.mat[0][0]%Mod+A.mat[1][1]*B.mat[1][0]%Mod)%Mod;
37 ret.mat[1][1]=(A.mat[1][0]*B.mat[0][1]%Mod+A.mat[1][1]*B.mat[1][1]%Mod)%Mod;
38 return ret;
39 }
40
41 void bulid(int left,int right,int i)//建树
42 {
43 int mid;
44 f[i].left=left;
45 f[i].right=right;
46 if(left==right)
47 {
48 f[i].matrix.set(left);
49 return;
50 }
51 mid=(left+right)>>1;
52 bulid(left,mid,i<<1);
53 bulid(mid+1,right,i<<1|1);
54 f[i].matrix=mat_mul_mod(f[i<<1|1].matrix,f[i<<1].matrix);
55 return ;
56 }
57
58 node query(int left,int right,int i)//查询
59 {
60 int mid;
61 if(f[i].left==left && f[i].right==right) return f[i].matrix;
62 mid=(f[i].left+f[i].right)>>1;
63 if(right<=mid) return query(left,right,i<<1);
64 else if(left>mid) return query(left,right,i<<1|1);
65 else return mat_mul_mod(query(mid+1,right,i<<1|1),query(left,mid,i<<1));
66 }
67
68 int main()
69 {
70 int t,n,m,i,lp,rp;
71 scanf("%d",&t);
72 while(t--)
73 {
74 scanf("%d %d",&n,&m);
75 for(i=1;i<=n;i++)
76 scanf("%lld",&a[i]);
77 bulid(1,n,1);
78 while(m--)
79 {
80 scanf("%d %d",&lp,&rp);
81 if(lp==rp || lp+1==rp)
82 {
83 printf("%lld\n",a[rp]%Mod);
84 continue;
85 }
86 node temp=query(lp+2,rp,1);
87 printf("%lld\n",(temp.mat[0][0]*a[lp+1]%Mod+temp.mat[0][1]*a[lp]%Mod)%Mod);
88 }
89 }
90 return 0;
91 }