#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define Max(a,b) ((a>=b)? a : b)
#define Min(a,b) ((a<=b)? a : b)
#define pb push_back
#define MOD 1000000007
#define MP make_pair
#define vi vector<int>
#define vll vector<ll>
#define MAX 32001
#define SZ 5
//typedef __int128 bigll;
ll a[100010];
ll treee[1000050];
int d=1;

// 1 indexed treee
void build(ll node,ll low,ll high)
{
    if(low==high)
    {
        treee[node] = a[low];
        return;
    }
    ll mid = (low+high)/2;
    build(2*node,low,mid);
    build(2*node+1,mid+1,high);
    treee[node] = __gcd(treee[2*node],treee[2*node+1]);
}

ll query(ll node,ll low,ll high,ll from,ll to)
{
    if(from<=low && to>=high)return treee[node];
    if(to<low || from>high)return -1;
    ll mid = (low+high)/2;
    ll r1 = query(2*node,low,mid,from,to);
    ll r2 = query(2*node+1,mid+1,high,from,to);
    if(r1==-1 && r2==-1)return 1;
    else if(r1==-1)return r2;
    else if(r2==-1)return r1;
    else return __gcd(r1,r2);
}

struct matrix
{
    ll mat[SZ][SZ];
};

matrix matmul(matrix A,matrix B)
{
    matrix C;
    for(int i=0; i<=d; i++)
    {
        for(int j=0; j<=d; j++)
        {
            ll val = 0ll;
            for(int k=0; k<=d; k++)
                val += (A.mat[i][k]*B.mat[k][j])%MOD;
            C.mat[i][j] = val;
        }
    }
    return C;
}

matrix matexpo(matrix BASE, ll p)
{
    if(p==1ll || p==0ll)return BASE;
    matrix R = matexpo(BASE,(ll)p >> 1ll);
    R = matmul(R,R);
    if(p&1ll)R = matmul(R,BASE);
    return R;
}

ll calc_fib(ll n)
{
    if(n<=1)return 1;
    matrix base;
    base.mat[0][0]=1;
    base.mat[0][1]=1;
    base.mat[1][0]=1;
    base.mat[1][1]=0;
    ll f[] = {1,0};
    base = matexpo(base,n-1);
    ll ans=0;
    for(int i=0; i<=d; i++)
        ans += (base.mat[0][i]*f[i])%MOD;
    return ans;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //FILE*f=freopen("input.txt","r",stdin);
    //FILE*o=freopen("output.txt","w",stdout);
    ll n,q,x,y;
    scanf("%lld %lld",&n,&q);
    for(int i=1; i<=n; i++)scanf("%lld",&a[i]);
    build(1,1,n);
    while(q--)
    {
        scanf("%lld %lld",&x,&y);
        ll id = query(1,1,n,x,y);
        printf("%lld\n",calc_fib(id));
    }
    //fclose(f);
    //fclose(o);

    return 0;
}