#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
#define E (n+m)
using namespace std; const int N=500010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,m,a[N];
int c[N];
inline int lowbit(int x) { return x&(-x); }
inline void Add(int x,int p)
{
	for(;x<=n;x+=lowbit(x)) c[x]^=p;
}
inline int Ask(int x)
{
	int tt=0;
	for(;x;x-=lowbit(x)) tt^=c[x];
	return tt;
}
signed main()
{
	n=read(), m=read();
	for(ri int i=1;i<=n;i++) a[i]=read(), Add(i,a[i]);
	for(ri int i=1;i<=m;i++)
	{
		int opt,x,y;
		opt=read(), x=read(), y=read();
		if(opt==1)
		{
			Add(x,y);
		}
		else
		{
			printf("%lld\n",Ask(x-1)^Ask(y));
		}
	}
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, p; cin >> n >> p;
  cout << modpow(p-2, n-1) * (p-1) % mod << endk;
  return 0;
}
