You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:   1 l r x — for each index i such that l ≤ i ≤ r set ai = x.  2 l r — find the minimum among such ai that l ≤ i ≤ r. We decided that this problem is too easy. So the array a is given in a compressed form: there is an array b consisting of n elements and a number k in the input, and before all queries a is equal to the concatenation of k arrays b (so the size of a is n·k).

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104). The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109). The third line contains one integer q (1 ≤ q ≤ 105). Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the segment from l till r (including borders) to x (1 ≤ l ≤ r ≤ n·k, 1 ≤ x ≤ 109) or as 2 l r — find the minimum among all elements in the segment from l till r (1 ≤ l ≤ r ≤ n·k).

For each query of type 2 print the answer to this query — the minimum on the corresponding segment.

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	/*if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}*/
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)
	{
		v.l=new vertex;
		v.l.val=t[1];
	}
	if(!v.r)
	{
		v.r=new vertex;
		v.r.val=t[1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.val=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.val=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)
	{
		v.l=new vertex;
		v.l.val=t[1];
	}
	if(!v.r)
	{
		v.r=new vertex;
		v.r.val=t[1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)v.l=new vertex;
	if(!v.r)v.r=new vertex;
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)v.v=new node;
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(v.x)
		{
			if(!v.v)v.v=new node;
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	/*if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}*/
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)
	{
		v.l=new vertex;
		v.l.val=t[1];
	}
	if(!v.r)
	{
		v.r=new vertex;
		v.r.val=t[1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)
	{
		v.l=new vertex;
		v.l.val=t[1];
	}
	if(!v.r)
	{
		v.r=new vertex;
		v.r.val=t[1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)v.v=new node;
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(v.x)
		{
			if(!v.v)v.v=new node;
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
void push1(node t)
{
	if(!t.l)
	{
		t.l=new node;
		t.l.val=int.max;
	}
	if(!t.r)
	{
		t.r=new node;
		t.r.val=int.max;
	}
	if(t.x!=0)t.l.x=t.r.x=t.val=t.x;
	t.x=0;
}
int cel1(node t,int tl,int tr,int l,int r)
{
	//writeln(l,' ',r);
	if(!t)
	{
		//writeln("ok");
		//writeln(l,' ',r);*/
		return cel0(1,0,n-1,l,r);
	}
	if(t.x)
	{
		//writeln(t.x);
		return t.x;
	}
	else if(tl==l && tr==r)
	{
		//writeln(t.x);
		return t.x?t.x:t.val;
	}
	else
	{
		if(t.x)push1(t);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel1(t.l,tl,tm,l,r);
		else if(l>tm)return cel1(t.r,tm+1,tr,l,r);
		else return min(cel1(t.l,tl,tm,l,tm),cel1(t.r,tm+1,tr,tm+1,r));
	}
}
void upd1(node t,int tl,int tr,int l,int r,int x)
{
	//writeln(tl,' ',tr,' ',l,' ',r);
	if(tl==l && tr==r)
	{
		t.x=x;
		//writeln(x,' ',l,' ',r);
	}
	else
	{
		if(t.x)push1(t);
		int tm=(tl+tr)>>1;
		if(r<=tm){if(!t.l){t.l=new node;}upd1(t.l,tl,tm,l,r,x);}
		else if(l>tm){if(!t.r){t.r=new node;}upd1(t.r,tm+1,tr,l,r,x);}
		else {
			if(!t.l){t.l=new node;}
			if(!t.r){t.r=new node;}
			upd1(t.l,tl,tm,l,tm,x);
			upd1(t.r,tm+1,tr,tm+1,r,x);

			}
		t.val=min(t.r?(t.r.x?t.r.x:t.r.val):cel0(1,0,n-1,tm+1,tr),t.l?(t.l.x?t.l.x:t.l.val):cel0(1,0,n-1,tl,tm));
		//writeln(t.val);
	}
}
void push2(vertex t)
{
	if(!t.l)
	{
		t.l=new vertex;
		t.l.val=cel0(1,0,n-1,0,n-1);
	}
	if(!t.r)
	{
		t.r=new vertex;
		t.r.val=cel0(1,0,n-1,0,n-1);
	}
	if(t.x!=0)t.r.x=t.l.x=t.val=t.x;
	t.x=0;
}
int cel2(vertex t,int tl,int tr,int l,int r,int l0=-1,int r0=-1)
{
	//writeln(tl,' ',tr,' ',l,' ',r);
	//writeln(t.x);
	if(t.x)return t.x;
	if(tl==tr && l0!=-1)
	{
		//writeln("ok");
		return cel1(t.v,0,n-1,l0,r0);
	}
	else if(tl==l && tr==r)
	{
		return t.x?t.x:t.val;
	}
	else
	{
		push2(t);
		//writeln(!t.l);
		int tm=(tl+tr)/2;
		if(r<=tm)return cel2(t.l,tl,tm,l,r,l0,r0);
		else if(l>tm)return cel2(t.r,tm+1,tr,l,r,l0,r0);
		else return min(cel2(t.l,tl,tm,l,tm,l0,r0),cel2(t.r,tm+1,tr,tm+1,r,l0,r0));
	}
}
void upd2(vertex t,int tl,int tr,int l,int r,int x,int l0=-1,int r0=-1)
{
	//writeln("warn");
	if(tl==tr && l0!=-1)
	{
		if(!t.v)t.v=new node;
		//writeln(l,' ',r);
		upd1(t.v,0,n-1,l0,r0,x);
		t.val=t.v.x?t.v.x:t.v.val;
		//writeln(t.val);
		return;
	}
	else if(tl==l && tr==r)
	{
		t.x=x;return;
	}
	else
	{
		push2(t);
		int tm=(tl+tr)/2;
		if(r<=tm){upd2(t.l,tl,tm,l,r,x,l0,r0);}
		else if(l>tm)upd2(t.r,tm+1,tr,l,r,x,l0,r0);
		else {upd2(t.l,tl,tm,l,tm,x);upd2(t.r,tm+1,tr,tm+1,r,x,l0,r0);}
		//t.val=cel0(1,0,n-1,0,n-1);
		t.val=min(t.r.x?t.r.x:t.r.val,t.l.x?t.l.x:t.l.val);

		return;
	}
}
int[] b,t;
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	vertex root=new vertex;
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[n*4];
	build(1,0,n-1);
	int q;
	read(q);
	//root.val=t[1];
	foreach(i;0..q)
	{
		int h;
		input(h);
		//writeln(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			l--;r--;
			int f=(l+n-1)/n,g=(r+1)/n;
			//writeln(f,' ',g);
			if(l/n==r/n)
			{
				//writeln("ko");
				upd2(root,0,k-1,r/n,r/n,x,l%n,r%n);
			}
			else
			{
				if(f<g)
				{
					upd2(root,0,k-1,f,g-1,x);
				}
				f=l/n;
				g=r/n;
				if(l%n)upd2(root,0,k-1,f,f,x,l%n,n-1);
				if((r)%n!=n-1)
				{
					upd2(root,0,k-1,g,g,x,0,r%n);
				}
			}
		}
		else
		{
			int l,r,ans=int.max;
			read(l,r);
			l--;r--;
			int f=(l+n-1)/n,g=(r+1)/n;

			if(l/n==r/n)
			{
				//writeln("ok)");
				ans=min(ans,cel2(root,0,k-1,r/n,r/n,l%n,r%n));
			}
			else
			{
				if(f<g)
				{
					ans=min(ans,cel2(root,0,k-1,f,g-1));

				}
				f=l/n;
				g=r/n;
				//writeln(f,' ',g);
				if(l%n)ans=min(ans,cel2(root,0,k-1,f,f,l%n,n-1));
				if((r)%n!=n-1)
				{
					ans=min(ans,cel2(root,0,k-1,g,g,0,r%n));
				}
			}
			write(ans,'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)v.l=new node;
	if(!v.r)v.r=new node;
	v.l.val=t[pos*2];
	v.r.val=t[pos*2+1];
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)v.l=new vertex;
	if(!v.r)v.r=new vertex;
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		v.v=new node;
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(v.x)
		{
			if(!v.v)v.v=new node;
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
int[] b,t;
void push(node v,int pos)
{
	if(!v.l)
	{
		v.l=new node;
		v.l.val=t[pos*2];
	}
	if(!v.r)
	{
		v.r=new node;
		v.r.val=t[pos*2+1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(node v,int pos,int tl,int tr,int l,int r,int x)
{
	if(tl==l && tr==r)v.x=x;
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)upd(v.l,pos*2,tl,tm,l,r,x);
		else if(l>tm)upd(v.r,pos*2+1,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,pos*2,tl,tm,l,tm,x);
			upd(v.r,pos*2+1,tm+1,tr,tm+1,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(node v,int pos,int tl,int tr,int l,int r)
{
	if(!v)
	{
		return cel0(pos,tl,tr,l,r);
	}
	if(tl==l && tr==r)
	{
		return v.x?v.x:v.val;
	}
	else
	{
		push(v,pos);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel(v.l,pos*2,tl,tm,l,r);
		else if(l>tm)return cel(v.r,pos*2+1,tm+1,tr,l,r);
		else return min(cel(v.l,pos*2,tl,tm,l,tm),cel(v.r,pos*2+1,tm+1,tr,tm+1,r));
	}
}
void push(vertex v)
{
	if(!v.l)
	{
		v.l=new vertex;
		v.l.val=t[1];
	}
	if(!v.r)
	{
		v.r=new vertex;
		v.r.val=t[1];
	}
	if(v.x)v.val=v.l.x=v.r.x=v.x;
	v.x=0;
}
void upd(vertex v,int tl,int tr,int l,int r,int x)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		v.x=x;
	}
	else if(tl==tr)
	{
		if(!v.v)
		{
			v.v=new node;
			v.v.val=t[1];
		}
		if(v.x)
		{
			v.v.x=v.x;
			v.x=0;
		}
		upd(v.v,1,0,n-1,l-tl*n,r-tl*n,x);
		v.val=v.v.x?v.v.x:v.v.val;
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)upd(v.l,tl,tm,l,r,x);
		else if(l/n>tm)upd(v.r,tm+1,tr,l,r,x);
		else
		{
			upd(v.l,tl,tm,l,tm*n+n-1,x);
			upd(v.r,tm+1,tr,(tm+1)*n,r,x);
		}
		v.val=min(v.r.x?v.r.x:v.r.val,v.l.x?v.l.x:v.l.val);
	}
}
int cel(vertex v,int tl,int tr,int l,int r)
{
	if(tl*n==l && tr*n+n-1==r)
	{
		return v.x?v.x:v.val;
	}
	else if(tl==tr)
	{
		if(v.x)
		{
			if(!v.v)v.v=new node;
			v.v.x=v.x;
			v.x=0;
		}
		return cel(v.v,1,0,n-1,l-tl*n,r-tl*n);
	}
	else
	{
		push(v);
		int tm=(tl+tr)>>1;
		if(r/n<=tm)return cel(v.l,tl,tm,l,r);
		else if(l/n>tm)return cel(v.r,tm+1,tr,l,r);
		else
		{
			return min(cel(v.l,tl,tm,l,tm*n+n-1),cel(v.r,tm+1,tr,(tm+1)*n,r));
		}
	}
}
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[4*n];
	int q;
	read(q);
	vertex root=new vertex;
	build(1,0,n-1);
	root.val=t[1];
	foreach(ii;0..q)
	{
		int h;
		input(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			upd(root,0,k-1,l-1,r-1,x);
		}
		else
		{
			int l,r;
			read(l,r);
			write(cel(root,0,k-1,l-1,r-1),'\n');
		}
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
class node
{
	int val,x;
	node l,r;
};
class vertex
{
	node v;
	int val,x;
	vertex l,r;
};
int n,k;
void push1(node t)
{
	if(!t.l)
	{
		t.l=new node;
		t.l.val=int.max;
	}
	if(!t.r)
	{
		t.r=new node;
		t.r.val=int.max;
	}
	if(t.x!=0)t.l.x=t.r.x=t.val=t.x;
	t.x=0;
}
int cel1(node t,int tl,int tr,int l,int r)
{
	//writeln(l,' ',r);
	if(!t)
	{
		//writeln("ok");
		//writeln(l,' ',r);*/
		return cel0(1,0,n-1,l,r);
	}
	if(t.x)
	{
		//writeln(t.x);
		return t.x;
	}
	else if(tl==l && tr==r)
	{
		//writeln(t.x);
		return t.x?t.x:t.val;
	}
	else
	{
		if(t.x)push1(t);
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel1(t.l,tl,tm,l,r);
		else if(l>tm)return cel1(t.r,tm+1,tr,l,r);
		else return min(cel1(t.l,tl,tm,l,tm),cel1(t.r,tm+1,tr,tm+1,r));
	}
}
void upd1(node t,int tl,int tr,int l,int r,int x)
{
	//writeln(tl,' ',tr,' ',l,' ',r);
	if(tl==l && tr==r)
	{
		t.x=x;
		//writeln(x,' ',l,' ',r);
	}
	else
	{
		if(t.x)push1(t);
		int tm=(tl+tr)>>1;
		if(r<=tm){if(!t.l){t.l=new node;}upd1(t.l,tl,tm,l,r,x);}
		else if(l>tm){if(!t.r){t.r=new node;}upd1(t.r,tm+1,tr,l,r,x);}
		else {
			if(!t.l){t.l=new node;}
			if(!t.r){t.r=new node;}
			upd1(t.l,tl,tm,l,tm,x);
			upd1(t.r,tm+1,tr,tm+1,r,x);

			}
		t.val=min(t.r?(t.r.x?t.r.x:t.r.val):cel0(1,0,n-1,tm+1,tr),t.l?(t.l.x?t.l.x:t.l.val):cel0(1,0,n-1,tl,tm));
		//writeln(t.val);
	}
}
void push2(vertex t)
{
	if(!t.l)
	{
		t.l=new vertex;
		t.l.val=cel0(1,0,n-1,0,n-1);
	}
	if(!t.r)
	{
		t.r=new vertex;
		t.r.val=cel0(1,0,n-1,0,n-1);
	}
	if(t.x!=0)t.r.x=t.l.x=t.val=t.x;
	t.x=0;
}
int cel2(vertex t,int tl,int tr,int l,int r,int l0=-1,int r0=-1)
{
	//writeln(tl,' ',tr,' ',l,' ',r);
	//writeln(t.x);
	if(t.x)return t.x;
	if(tl==tr && l0!=-1)
	{
		//writeln("ok");
		return cel1(t.v,0,n-1,l0,r0);
	}
	else if(tl==l && tr==r)
	{
		return t.x?t.x:t.val;
	}
	else
	{
		push2(t);
		//writeln(!t.l);
		int tm=(tl+tr)/2;
		if(r<=tm)return cel2(t.l,tl,tm,l,r,l0,r0);
		else if(l>tm)return cel2(t.r,tm+1,tr,l,r,l0,r0);
		else return min(cel2(t.l,tl,tm,l,tm,l0,r0),cel2(t.r,tm+1,tr,tm+1,r,l0,r0));
	}
}
void upd2(vertex t,int tl,int tr,int l,int r,int x,int l0=-1,int r0=-1)
{
	//writeln("warn");
	if(tl==tr && l0!=-1)
	{
		if(!t.v)t.v=new node;
		//writeln(l,' ',r);
		upd1(t.v,0,n-1,l0,r0,x);
		t.val=t.v.x?t.v.x:t.v.val;
		//writeln(t.val);
		return;
	}
	else if(tl==l && tr==r)
	{
		t.x=x;return;
	}
	else
	{
		push2(t);
		int tm=(tl+tr)/2;
		if(r<=tm){upd2(t.l,tl,tm,l,r,x,l0,r0);}
		else if(l>tm)upd2(t.r,tm+1,tr,l,r,x,l0,r0);
		else {upd2(t.l,tl,tm,l,tm,x);upd2(t.r,tm+1,tr,tm+1,r,x,l0,r0);}
		//t.val=cel0(1,0,n-1,0,n-1);
		t.val=min(t.r.x?t.r.x:t.r.val,t.l.x?t.l.x:t.l.val);

		return;
	}
}
int[] b,t;
void build(int v,int tl,int tr)
{
	if(tl==tr)t[v]=b[tl];
	else
	{
		int tm=(tl+tr)>>1;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		t[v]=min(t[v*2+1],t[v*2]);
	}
}
int cel0(int v,int tl,int tr,int l,int r)
{
	//writeln("ok");
	if(tl==l && tr==r)return t[v];
	else
	{
		int tm=(tl+tr)>>1;
		if(r<=tm)return cel0(v*2,tl,tm,l,r);
		else if(l>tm)return cel0(v*2+1,tm+1,tr,l,r);
		else return min(cel0(v*2,tl,tm,l,tm),cel0(v*2+1,tm+1,tr,tm+1,r));
	}
}

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	vertex root=new vertex;
	//writeln(!root);
	/*int n;
loop:while(read(n))
	{

	}*/
	read(n,k);
	b=arread!int;
	t=new int[n*4];
	build(1,0,n-1);
	int q;
	read(q);
	root.val=t[1];
	foreach(i;0..q)
	{
		int h;
		input(h);
		//writeln(h);
		if(h==1)
		{
			int l,r,x;
			read(l,r,x);
			l--;r--;
			int f=(l+n-1)/n,g=(r+1)/n;
			//writeln(f,' ',g);
			if(l/n==r/n)
			{
				//writeln("ko");
				upd2(root,0,k-1,r/n,r/n,x,l%n,r%n);
			}
			else
			{
				if(f<g)
				{
					upd2(root,0,k-1,f,g-1,x);
				}
				f=l/n;
				g=r/n;
				if(l%n)upd2(root,0,k-1,f,f,x,l%n,n-1);
				if((r)%n!=n-1)
				{
					upd2(root,0,k-1,g,g,x,0,r%n);
				}
			}
		}
		else
		{
			int l,r,ans=int.max;
			read(l,r);
			l--;r--;
			int f=(l+n-1)/n,g=(r+1)/n;

			if(l/n==r/n)
			{
				//writeln("ok)");
				ans=min(ans,cel2(root,0,k-1,r/n,r/n,l%n,r%n));
			}
			else
			{
				if(f<g)
				{
					ans=min(ans,cel2(root,0,k-1,f,g-1));

				}
				f=l/n;
				g=r/n;
				//writeln(f,' ',g);
				if(l%n)ans=min(ans,cel2(root,0,k-1,f,f,l%n,n-1));
				if((r)%n!=n-1)
				{
					ans=min(ans,cel2(root,0,k-1,g,g,0,r%n));
				}
			}
			write(ans,'\n');
		}
	}
}


CQXYM wants to create a connected undirected graph with $$$n$$$ nodes and $$$m$$$ edges, and the diameter of the graph must be strictly less than $$$k-1$$$. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one edge).The diameter of a graph is the maximum distance between any two nodes.The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.CQXYM wonders whether it is possible to create such a graph.

The input consists of multiple test cases.  The first line contains an integer $$$t (1 \leq t \leq 10^5)$$$ — the number of test cases. The description of the test cases follows. Only one line of each test case contains three integers $$$n(1 \leq n \leq 10^9)$$$, $$$m$$$, $$$k$$$ $$$(0 \leq m,k \leq 10^9)$$$.

For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).

NoteIn the first test case, the graph's diameter equal to 0.In the second test case, the graph's diameter can only be 2.In the third test case, the graph's diameter can only be 1.

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		auto m = RD;
		auto k = RD-1;

		if (m < n-1) continue;
		auto cnt = n * (n-1) / 2;
		if (m > cnt) continue;
		long kk;
		if (n == 1)
			kk = 0;
		else if (m == cnt)
			kk = 1;
		else
			kk = 2;
		debug writeln("kk:", kk);
		if (kk < k)
			ans[ti] = true;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  long t;
  readf(" %d ", &t);
  while (t--) {
    long n, m, k;
    readf(" %d %d %d ", &n, &m, &k);
    if (m < n - 1) {
      writeln("NO");
      continue;
    }
    if (m > n * (n - 1) / 2) {
      writeln("NO");
      continue;
    }
    long min_d = 2;
    if (m == n * (n - 1) / 2) {
      min_d = 1;
    }
    if (n == 1) {
      min_d = 0;
    }
    writeln(min_d < k - 1 ? "YES" : "NO");
  }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto k = RD!int-1;

		if (m < n-1) continue;
		auto cnt = n * (n-1) / 2;
		if (m > cnt) continue;
		long kk;
		if (n == 1)
			kk = 0;
		else if (m == cnt)
			kk = 1;
		else
			kk = 2;
		debug writeln("kk:", kk);
		if (kk < k)
			ans[ti] = true;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}


You are given three positive integers $$$n$$$, $$$a$$$ and $$$b$$$. You have to construct a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters such that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.Recall that the substring $$$s[l \dots r]$$$ is the string $$$s_l, s_{l+1}, \dots, s_{r}$$$ and its length is $$$r - l + 1$$$. In this problem you are only interested in substrings of length $$$a$$$.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains three space-separated integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le a \le n \le 2000, 1 \le b \le \min(26, a)$$$), where $$$n$$$ is the length of the required string, $$$a$$$ is the length of a substring and $$$b$$$ is the required number of distinct letters in each substring of length $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer — such a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

NoteIn the first test case of the example, consider all the substrings of length $$$5$$$:  "tleel": it contains $$$3$$$ distinct (unique) letters,  "leelt": it contains $$$3$$$ distinct (unique) letters,  "eelte": it contains $$$3$$$ distinct (unique) letters.

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nab = readln.split.to!(int[]);
        auto N = nab[0];
        auto A = nab[1];
        auto B = nab[2];

        char[] rs, ss;
        foreach (i; 0..A) {
            rs ~= (min(i, B-1) + 'a').to!char;
        }
        foreach (i; 0..N) {
            ss ~= rs[i%A];
        }
        writeln(ss);
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int n, a, b;
		readf !(" %s %s %s") (n, a, b);
		string s;
		s.reserve (n);
		foreach (i; 0..n)
		{
			s ~= cast (char) (i % b + 'a');
		}
		writeln (s);
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new string[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD!int;
		auto b = RD!int;

		auto loop = a - b;
		int num;
		int cnt;
		while (ans[ti].length < n)
		{
			if (cnt % a < loop)
			{
				ans[ti] ~= 'a';
			}
			else
			{
				ans[ti] ~= cast(char)('a'+(num%b));
				++num;
			}
			++cnt;
		}
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}


Nikita likes tasks on order statistics, for example, he can easily find the $$$k$$$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $$$x$$$ is the $$$k$$$-th number in increasing order on this segment. In other words, you should find the number of segments of a given array such that there are exactly $$$k$$$ numbers of this segment which are less than $$$x$$$.Nikita wants to get answer for this question for each $$$k$$$ from $$$0$$$ to $$$n$$$, where $$$n$$$ is the size of the array.

The first line contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le n \le 2 \cdot 10^5, -10^9 \le x \le 10^9)$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(-10^9 \le a_i \le 10^9)$$$ — the given array.

Print $$$n+1$$$ integers, where the $$$i$$$-th number is the answer for Nikita's question for $$$k=i-1$$$.

import std.algorithm;
import std.array;
import std.complex;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

immutable int limit = 1 << 19;
immutable int half = 512;

void main ()
{
	int n, x;
	while (readf (" %s %s", &n, &x) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto v = new real [limit];
		v[] = 0;
		int pos = 0;
		int cur = 1;
		foreach (ref c; a)
		{
			if (c < x)
			{
				v[pos] = cur;
				pos += 1;
				cur = 1;
			}
			else
			{
				cur += 1;
			}
		}
		v[pos] = cur;
		pos += 1;
		auto u = v.map !(c => Complex !(real) (cast (long) (c) % half, cast (long) (c) / half)).array;
		reverse (u[0..pos]);
//		debug {writeln (u.take (n).map !(c => c.round.to !(long)));}
		debug {writeln (v.take (n).map !(c => c.round.to !(long)));}

		auto f = new Fft (limit);
		auto uf = f.fft !(real) (u);
		auto vf = f.fft !(real) (v);
		auto wf = uf.dup;
		wf[] *= vf[];
		auto w = f.inverseFft !(real) (wf);
		debug {writeln (w.take (n + 1).map !(c => c.re.round.to !(long)));}
		auto wr = w.take (n + 1).map !(c => c.re.round.to !(long) + half * c.im.round.to !(long)).array;
		wr[pos - 1] = 0;
		foreach (i; 0..pos)
		{
			wr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);
		}
		reverse (wr[0..pos]);
		wr[pos..$][] = 0;
		writefln ("%(%s %)", wr);
	}
}

import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;
immutable int L = 1 << 19, H = 512;
void main () {
	int n, x;
	readf (" %s %s ", &n, &x);
	auto a = readln.splitter.map !(to!int).array;
	auto v = a.splitter !(t => t < x).map !(t => t.length + 1L).array;
	auto k = v.length;
	v.length = L;
	auto u = v.map !(c => Complex!real (c % H, c / H)).array;
	reverse (u[0..k]);
	auto g = u.fft!real, h = v.fft!real;
	g[] *= h[];
	auto w = g.inverseFft!real[0..k].retro.map !(c => to!long (c.re.round + H * c.im.round)).array;
	w[0] = k.iota.map !(i => (v[i] * (v[i] - 1) / 2)).sum;
	w.length = n + 1;
	writefln ("%(%s %)", w);
}

import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;

immutable int limit = 1 << 19, half = 512;

void main ()
{
	int n, x;
	readf (" %s %s ", &n, &x);
	auto a = readln.splitter.map !(to!int).array ~ int.min;
	auto v = new long [limit];
	int pos = 0, cur = 0;
	foreach (c; a)
	{
		++cur;
		if (c < x) v[pos++] = cur, cur = 0;
	}
	auto u = v.map !(c => Complex!real (c % half, c / half)).array;
	reverse (u[0..pos]);
	auto f = new Fft (limit);
	auto g = f.fft!real (u), h = f.fft!real (v);
	g[] *= h[];
	auto w = f.inverseFft!real (g).take (n + 1).map !(c => cast (long) (c.re.round + half * c.im.round)).array;
	w[pos - 1] = 0;
	foreach (i; 0..pos) w[pos - 1] += (v[i] * (v[i] - 1) / 2);
	reverse (w[0..pos]);
	w[pos..$] = 0;
	writefln ("%(%s %)", w);
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

class Fft(int K) {
  // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...
  Complex!real[] g;
  this() {
    static assert(K >= 2, "Fft: K >= 2 must hold");
    g.length = 1 << (K - 1);
    g[0] = 1;
    g[1 << (K - 2)] = fromPolar(1.0L, (2.0L * PI) / (1 << K));
    for (int l = 1 << (K - 2); l >= 2; l >>= 1) {
      g[l >> 1] = g[l] * g[l];
    }
    for (int l = 2; l <= 1 << (K - 2); l <<= 1) {
      for (int i = 1; i < l; ++i) {
        g[l + i] = g[l] * g[i];
      }
    }
  }
  void fft(Complex!real[] x) const {
    const n = cast(int)(x.length);
    assert(!(n & (n - 1)) && n <= 1 << K);
    for (int l = n; l >>= 1; ) {
      for (int i = 0; i < (n >> 1) / l; ++i) {
        for (int j = (i << 1) * l; j < (i << 1 | 1) * l; ++j) {
          const t = g[i] * x[j + l];
          x[j + l] = x[j] - t;
          x[j] += t;
        }
      }
    }
    for (int i = 0, j = 0; i < n; ++i) {
      if (i < j) swap(x[i], x[j]);
      for (int l = n; (l >>= 1) && !((j ^= l) & l); ) {}
    }
  }
}
enum FFT_K = 19;
Fft!FFT_K FFT;

void main() {
  FFT = new Fft!FFT_K();

  try {
    for (; ; ) {
      const N = readInt();
      const X = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto ss = new int[N + 1];
      foreach (i; 0 .. N) {
        ss[i + 1] = ss[i] + ((A[i] < X) ? 1 : 0);
      }
      debug {
        writeln("ss = ", ss);
      }

      auto fs = new Complex!real[1 << FFT_K];
      auto gs = new Complex!real[1 << FFT_K];
      fs[] = complex(0.0L, 0.0L);
      gs[] = complex(0.0L, 0.0L);
      foreach (i; 0 .. N + 1) {
        fs[ss[i]] += 1.0L;
        gs[N - ss[i]] += 1.0L;
      }
      FFT.fft(fs);
      FFT.fft(gs);
      foreach (j; 0 .. 1 << FFT_K) {
        fs[j] *= gs[j] / (1 << FFT_K);
      }
      fs[1 .. $].reverse;
      FFT.fft(fs);
      auto ans = new long[N + 1];
      foreach (k; 1 .. N + 1) {
        ans[k] = cast(long)(fs[N + k].re + 0.5L);
      }
      ans[0] = 1L * N * (N + 1) / 2 - ans[1 .. N + 1].sum;

      foreach (k; 0 .. N + 1) {
        if (k > 0) write(" ");
        write(ans[k]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.array;
import std.complex : g = abs;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

immutable int limit = 1 << 20;

void main ()
{
	int n, x;
	while (readf (" %s %s", &n, &x) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto v = new real [limit];
		v[] = 0;
		int pos = 0;
		int cur = 1;
		foreach (ref c; a)
		{
			if (c < x)
			{
				v[pos] = cur;
				pos += 1;
				cur = 1;
			}
			else
			{
				cur += 1;
			}
		}
		v[pos] = cur;
		pos += 1;
		auto u = v.dup;
		reverse (u[0..pos]);
		debug {writeln (u.take (n).map !(c => c.round.to !(long)));}
		debug {writeln (v.take (n).map !(c => c.round.to !(long)));}

		auto f = new Fft (limit);
		auto uf = f.fft !(real) (u);
		auto vf = f.fft !(real) (v);
		auto wf = uf.dup;
		wf[] *= vf[];
		auto w = f.inverseFft !(real) (wf);
		debug {writeln (w.take (n + 1).map !(c => g (c).round.to !(long)));}
		auto wr = w.take (n + 1).map !(c => g (c).round.to !(long)).array;
		wr[pos - 1] = 0;
		foreach (i; 0..pos)
		{
			wr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);
		}
		reverse (wr[0..pos]);
		wr[pos..$][] = 0;
		writefln ("%(%s %)", wr);
	}
}

import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;
immutable int L = 1 << 19, H = 512;
void main () {
	int n, x;
	readf (" %s %s ", &n, &x);
	auto a = readln.splitter.map !(to!int).array;
	auto v = a.splitter !(t => t < x).map !(t => t.length + 1).array;
	auto k = v.length;
	v.length = L;
	auto u = v.map !(c => Complex!real (c % H, c / H)).array;
	reverse (u[0..k]);
	auto g = u.fft!real, h = v.fft!real;
	g[] *= h[];
	auto w = g.inverseFft!real[0..k].retro.map !(c => to!long (c.re.round + H * c.im.round)).array;
	w[0] = k.iota.map !(i => (v[i] * (v[i] - 1) / 2)).sum;
	w.length = n + 1;
	writefln ("%(%s %)", w);
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

immutable int limit = 1 << 19;

void main ()
{
	int n, x;
	while (readf (" %s %s", &n, &x) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto v = new real [limit];
		v[] = 0;
		int pos = 0;
		int cur = 1;
		foreach (ref c; a)
		{
			if (c < x)
			{
				v[pos] = cur;
				pos += 1;
				cur = 1;
			}
			else
			{
				cur += 1;
			}
		}
		v[pos] = cur;
		pos += 1;
		auto u = v.dup;
		reverse (u[0..pos]);
		debug {writeln (u.take (n).map !(c => c.round.to !(long)));}
		debug {writeln (v.take (n).map !(c => c.round.to !(long)));}

		auto f = new Fft (limit);
		auto uf = f.fft !(real) (u);
		auto vf = f.fft !(real) (v);
		auto wf = uf.dup;
		wf[] *= vf[];
		auto w = f.inverseFft !(real) (wf);
		debug {writeln (w.take (n + 1).map !(c => c.re.round.to !(long)));}
		auto wr = w.take (n + 1).map !(c => c.re.round.to !(long)).array;
		wr[pos - 1] = 0;
		foreach (i; 0..pos)
		{
			wr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);
		}
		reverse (wr[0..pos]);
		wr[pos..$][] = 0;
		writefln ("%(%s %)", wr);
	}
}


Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by  - 1. The second operation is to take some suffix and multiply all numbers in it by  - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?

The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.

The first and the only line of the output should contain the answer to the problem.

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto prefSum = 0 ~ arr.cumulativeFold!((a, b) => a + b).array;

    auto flipSufSum = arr.retro().cumulativeFold!((a, b) => a - b)(0).array.reverse() ~ 0;

    int getVal(int idx) { return prefSum[idx] + flipSufSum[idx]; }

    auto bestSufFlipIdx = new int[] (n+1);
    bestSufFlipIdx[n] = n;
    foreach_reverse (i; 0 .. n) {
        bestSufFlipIdx[i] = bestSufFlipIdx[i+1];

        debug { writeln(i, ' ', getVal(i)); }

        if (getVal(i) > getVal(bestSufFlipIdx[i+1])) { bestSufFlipIdx[i] = i; }
    }

    debug { prefSum.writeln; flipSufSum.writeln; bestSufFlipIdx.writeln; }

    int ans = getVal(bestSufFlipIdx[0]);
    int csumle = 0;
    foreach (i, e; arr.dropBackOne.enumerate(1)) {
        csumle += -e;

        int bestIdx = bestSufFlipIdx[i+1];

        debug { writeln(i, ' ', csumle, ' ', bestIdx, ' ', prefSum[bestIdx] - prefSum[i], ' ', flipSufSum[bestIdx]); }

        ans = max(ans, csumle + getVal(bestIdx) - prefSum[i]);
    }

    ans.writeln;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto prefSum = 0 ~ arr.cumulativeFold!((a, b) => a + b).array;

    auto flipSufSum = arr.retro().cumulativeFold!((a, b) => a - b)(0).array.reverse() ~ 0;

    auto bestSufFlipIdx = new int[] (n+1);
    bestSufFlipIdx[n] = n;
    foreach_reverse (i; 0 .. n) {
        bestSufFlipIdx[i] = bestSufFlipIdx[i+1];

        int getVal(int idx) { return prefSum[idx] + flipSufSum[idx]; }

        debug { writeln(i, ' ', getVal(i)); }

        if (getVal(i) > getVal(bestSufFlipIdx[i+1])) { bestSufFlipIdx[i] = i; }
    }

    debug { prefSum.writeln; flipSufSum.writeln; bestSufFlipIdx.writeln; }

    int ans = max(prefSum[n], flipSufSum[0]);
    int csumle = 0;
    foreach (i, e; arr.dropBackOne.enumerate(1)) {
        csumle += -e;

        int bestIdx = bestSufFlipIdx[i+1];

        debug { writeln(i, ' ', csumle, ' ', bestIdx, ' ', prefSum[bestIdx] - prefSum[i], ' ', flipSufSum[bestIdx]); }

        ans = max(ans, csumle + prefSum[bestIdx] - prefSum[i] + flipSufSum[bestIdx]);
    }

    ans.writeln;
}


Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors. Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

First line of input consists of one integer n (1 ≤ n ≤ 3000). Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output single integer — minimum amount of coins the colonel has to pay.

NoteIn first sample test we can increase factor of first badge by 1.In second sample test we can increase factors of the second and the third badge by 1.

import std.stdio, std.string, std.algorithm, std.array, std.conv;

void main() {

	readln.strip;

	bool[int] arr;

	int sum;
	foreach (el; readln.split.map!(to!int).array.sort!"a < b") {
		int tmp;
		while (arr.get(el + tmp, false)) {
			++sum;
			++tmp;
		}
		arr[el + tmp] = true;
	}

	writeln(sum);
}

import std.stdio, std.string, std.algorithm, std.array, std.conv;

void main() {

	readln.strip;

	bool[int] arr;

	int sum;
	foreach (el; readln.split.map!(to!int).array.sort!"a < b") {
		int tmp;
		while (arr.get(el + tmp, false)) {
			++sum;
			++tmp;
		}
		arr[el + tmp] = true;
	}

	writeln(sum);
	arr.rehash;
	writeln(arr);
}

import std.stdio, std.string, std.algorithm, std.array, std.conv;

void main() {

	readln.strip;

	bool[int] arr;

	int sum;
	foreach (el; readln.split.map!(to!int).array.sort!"a < b") {
		if (arr.get(el, false)) {
			++sum;
			arr[el + 1] = true;
		}
		arr[el] = true;
	}

	writeln(sum);
}


SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will win the match.

Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    //stdin.open("input.txt", "r");
    //stdout.open("output.txt", "w");
    int a;
    int b;
    int c;
    int d;
    readf("%d %d %d %d ", &a, &b, &c, &d);
    auto p1 = cast(double)a / b;
    auto p2 = cast(double)c / d;
    auto cur_p = 1.0;
    auto res = 0.0;
    foreach (i; 0..1000000) {
        res += cur_p * p1;
        cur_p *= (1 - p1) * (1 - p2);
    }
    writefln("%.20f", res);
}


Igor is in the museum and he wants to see as many pictures as possible.Museum can be represented as a rectangular field of n × m cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.

First line of the input contains three integers n, m and k (3 ≤ n, m ≤ 1000, 1 ≤ k ≤ min(n·m, 100 000)) — the museum dimensions and the number of starting positions to process. Each of the next n lines contains m symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last k lines contains two integers x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.

Print k integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.

import std.stdio;
import std.string;

immutable int DIRS = 4;
immutable int [DIRS] DROW = [-1,  0, +1,  0];
immutable int [DIRS] DCOL = [ 0, -1,  0, +1];

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s ", &n, &m, &k) > 0)
	{
		string [] a;
		foreach (row; 0..n)
		{
			a ~= readln.strip;
		}
		auto b = new int [] [] (n, m);

		int recur (int row, int col, int mark)
		{
			int res = 0;
			if (b[row][col])
			{
				return res;
			}
			b[row][col] = mark;
			foreach (dir; 0..DIRS)
			{
				int nrow = row + DROW[dir];
				int ncol = col + DCOL[dir];
				if (a[nrow][ncol] == '.')
				{
					res += recur (nrow, ncol, mark);
				}
				else
				{
					res++;
				}
			}
			return res;
		}

		int [] ans;
		foreach (z; 0..k)
		{
			int row, col;
			readf (" %s %s", &row, &col);
			row--;
			col--;
			if (!b[row][col])
			{
				ans ~= recur (row, col, ans.length + 1);
			}
			writeln (ans[b[row][col] - 1]);
		}
	}
}


Find the number of ways to divide an array $$$a$$$ of $$$n$$$ integers into any number of disjoint non-empty segments so that, in each segment, there exist at most $$$k$$$ distinct integers that appear exactly once.Since the answer can be large, find it modulo $$$998\,244\,353$$$.

The first line contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 10^5$$$) — the number of elements in the array $$$a$$$ and the restriction from the statement. The following line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — elements of the array $$$a$$$.

The first and only line contains the number of ways to divide an array $$$a$$$ modulo $$$998\,244\,353$$$.

NoteIn the first sample, the three possible divisions are as follows.  $$$[[1], [1], [2]]$$$  $$$[[1, 1], [2]]$$$  $$$[[1, 1, 2]]$$$ Division $$$[[1], [1, 2]]$$$ is not possible because two distinct integers appear exactly once in the second segment $$$[1, 2]$$$.

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum MO = 998244353L;
enum L = 300;

void ADD(ref long t, long f) {
  t += f;
  if (t >= MO) {
    t -= MO;
  }
}

int N, K;
int[] A;

long[] dp;

int numBlocks;
int[] mins;
int[] keys;
long[][] sums;

void init() {
  numBlocks = (N + 1 + L - 1) / L;
  mins = new int[numBlocks];
  keys = new int[N + 1];
  sums = new long[][](numBlocks, L + 1);
}

void addDP(int i) {
  debug {
    writeln("addDP ", i, "; ", dp[i]);
  }
  foreach (x; keys[i] .. L + 1) {
    ADD(sums[i / L][x], dp[i]);
  }
}

void rangeAdd(int a, int b, int val) {
  debug {
    writeln("  mins = ", mins);
    writeln("  keys = ", keys);
    writeln("rangeAdd ", a, " ", b, " ", val);
  }
  foreach (e; 0 .. numBlocks) {
    const l = L * e, r = min(L * (e + 1), N);
    const aa = max(a, l), bb = min(b, r);
    if (aa < bb) {
      if (aa == l && bb == r) {
        mins[e] += val;
      } else {
        foreach (i; aa .. bb) {
          keys[i] += val;
        }
        const mn = keys[l .. r].minElement;
        mins[e] += mn;
        foreach (i; l .. r) {
          keys[i] -= mn;
        }
        sums[e][] = 0;
        foreach (i; l .. r) {
          ADD(sums[e][keys[i]], dp[i]);
        }
        foreach (x; 1 .. L + 1) {
          ADD(sums[e][x], sums[e][x - 1]);
        }
      }
    }
  }
}

long getDPSum() {
  long ret;
  foreach (e; 0 .. numBlocks) {
    if (mins[e] <= K) {
      ADD(ret, sums[e][min(K - mins[e], L)]);
    }
  }
  debug {
    writeln("getDPSum = ", ret);
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto app = new int[N + 1];
      app[] = -1;
      auto prev = new int[N];
      foreach (i; 0 .. N) {
        prev[i] = app[A[i]];
        app[A[i]] = i;
      }

      init();
      dp = new long[N + 1];
      dp[0] = 1;
      addDP(0);
      foreach (i; 0 .. N) {
        if (prev[i] >= 0) {
          rangeAdd(prev[prev[i]] + 1, prev[i] + 1, -1);
        }
        rangeAdd(prev[i] + 1, i + 1, +1);
        dp[i + 1] = getDPSum();
        addDP(i + 1);
      }
      writeln(dp[N]);
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum MO = 998244353L;
enum L = 2;

int N, K;
int[] A;

long[] dp;

int numBlocks;
int[] mins;
int[] keys;
long[][] sums;

void init() {
  numBlocks = (N + 1 + L - 1) / L;
  mins = new int[numBlocks];
  keys = new int[N + 1];
  sums = new long[][](numBlocks, L + 1);
}

void addDP(int i) {
  debug {
    writeln("addDP ", i, "; ", dp[i]);
  }
  foreach (x; keys[i] .. L + 1) {
    sums[i / L][x] += dp[i];
  }
}

void rangeAdd(int a, int b, int val) {
  debug {
    writeln("  mins = ", mins);
    writeln("  keys = ", keys);
    writeln("rangeAdd ", a, " ", b, " ", val);
  }
  foreach (e; 0 .. numBlocks) {
    const l = L * e, r = min(L * (e + 1), N);
    const aa = max(a, l), bb = min(b, r);
    if (aa < bb) {
      if (aa == l && bb == r) {
        mins[e] += val;
      } else {
        foreach (i; aa .. bb) {
          keys[i] += val;
        }
        const mn = keys[l .. r].minElement;
        mins[e] += mn;
        foreach (i; l .. r) {
          keys[i] -= mn;
        }
        sums[e][] = 0;
        foreach (i; l .. r) {
          sums[e][keys[i]] += dp[i];
        }
        foreach (x; 1 .. L + 1) {
          sums[e][x] += sums[e][x - 1];
        }
      }
    }
  }
}

long getDPSum() {
  long ret;
  foreach (e; 0 .. numBlocks) {
    if (mins[e] <= K) {
      ret += sums[e][min(K - mins[e], L)];
    }
  }
  debug {
    writeln("getDPSum = ", ret);
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto app = new int[N + 1];
      app[] = -1;
      auto prev = new int[N];
      foreach (i; 0 .. N) {
        prev[i] = app[A[i]];
        app[A[i]] = i;
      }

      init();
      dp = new long[N + 1];
      dp[0] = 1;
      addDP(0);
      foreach (i; 0 .. N) {
        if (prev[i] >= 0) {
          rangeAdd(prev[prev[i]] + 1, prev[i] + 1, -1);
        }
        rangeAdd(prev[i] + 1, i + 1, +1);
        dp[i + 1] = getDPSum();
        addDP(i + 1);
      }
      writeln(dp[N]);
    }
  } catch (EOFException e) {
  }
}