#include // c #include // io #include #include #include #include // container #include #include #include #include #include #include #include // other #include #include #include #include #include using namespace std; typedef long long ll;typedef unsigned long long ull;typedef long double ld; #define ALL(c) c.begin(),c.end() #define IN(l,v,r) (l<=v && v < r) template void UNIQUE(T& v){v.erase(unique(ALL(v)),v.end());} //debug== #define DUMP(x) cerr << #x <<" = " << (x) #define LINE() cerr<< " (L" << __LINE__ << ")" struct range{ struct Iter{ int v,step; Iter& operator++(){v+=step;return *this;} bool operator!=(Iter& itr){return vitr.v;} int& operator*(){return v;} }; Iter i, n; rrange(int i, int n,int step):i({i-1,step}), n({n-1,step}){} rrange(int i, int n):rrange(i,n,1){} rrange(int n) :rrange(0,n){} Iter& begin(){return n;} Iter& end(){return i;} }; //input template istream& operator >> (istream& is,pair& p){return is>>p.first>>p.second;} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t);} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t) >> get<1>(t);} template istream& operator >> (istream& is,tuple& t){return is >>get<0>(t)>>get<1>(t)>>get<2>(t);} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t)>>get<1>(t)>>get<2>(t)>>get<3>(t);} template istream& operator >> (istream& is,vector& as){for(int i:range(as.size()))is >>as[i];return is;} //output template ostream& operator << (ostream& os, const set& ss){for(auto a:ss){if(a!=ss.begin())os<<" "; os< ostream& operator << (ostream& os, const pair& p){return os< ostream& operator << (ostream& os, const map& m){bool isF=true;for(auto& p:m){if(!isF)os< ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t)<<" "<(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t);} template ostream& operator << (ostream& os, const vector& as){for(int i:range(as.size())){if(i!=0)os<<" "; os< ostream& operator << (ostream& os, const vector>& as){for(int i:range(as.size())){if(i!=0)os< inline T INF(){assert(false);}; template<> inline int INF(){return 1<<28;}; template<> inline ll INF(){return 1LL<<60;}; template<> inline double INF(){return 1e16;}; template<> inline long double INF(){return 1e16;}; template inline T EPS(){assert(false);}; template<> inline int EPS(){return 1;}; template<> inline ll EPS(){return 1LL;}; template<> inline double EPS(){return 1e-12;}; template<> inline long double EPS(){return 1e-12;}; // min{2^r | n < 2^r} template inline T upper_pow2(T n){ T res=1;while(res inline T msb(T n){ int d=62;while((1LL<n)d--;return d;} template T pmod(T v,U M){return (v%M+M)%M;} template struct Edge{ int to;Cost cost; Edge(int to,Cost cost):to(to),cost(cost){}; bool operator<(Edge r) const{ return cost(Edge r) const{ return cost>r.cost;} }; template ostream& operator << (ostream& os, const Edge& e){ return os<<"(->"< using Graph = vector>>; struct mint{ ll x, mod; mint(ll x,ll mod=1e9+7):x((x%mod+mod)%mod),mod(mod){} mint():mint(0){} mint operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;} mint operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;} mint operator*=(const mint& a){ (x*=a.x)%=mod; return *this;} mint operator+(const mint& a)const{ return mint(*this) += a;} mint operator-(const mint& a)const{ return mint(*this) -= a;} mint operator*(const mint& a)const{ return mint(*this) *= a;} bool operator==(const mint& a)const{ return x == a.x;} // O(logN) mint pow(ll N){ mint r(1),x = *this; while(N){ if(N&1) r *= x; N /= 2; x *= x; } return r; } mint minv(){return pow(mod-2);} }; istream& operator >> (istream& is,mint& p){return is>>p.x;} ostream& operator << (ostream& os,mint m){os << m.x;return os;} class VH{ public: ll operator()(const vector& x) const{ return x[0].x*1000000007LL + x[1].x; } }; class Main{ public: void run(){ int N,Q;cin >> N >> Q; vector mods = {999999937LL, 1000000007LL};ll base = 1e7+1; unordered_map,int,VH> vmap; vector mv(2); for(int i:range(2))mv[i] =mint(0,mods[i]); vmap[mv] = 0; for(int q:range(Q)){ char c;cin >> c; if(c=='!'){ int l,r,v;cin >> l >> r >> v; for(int i:range(2)){ mv[i] += mint(v,mods[i]) * (mint(base,mods[i]).pow(r) - mint(base,mods[i]).pow(l)) * mint(base-1).pow(mods[i]-1); } if(!vmap.count(mv)){ vmap[mv] = q+1; } }else{ cout << vmap[mv] << endl; } } } }; int main(){ cout <