#include <bits/stdc++.h>

#define MaxN 100
#define INF 2140000000LL

using namespace std;

int Max,r=-1,Min,N,v[MaxN],remaining=60;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    else return gcd(b,a%b);
}

int binsearch()
{
    int lw=0,hi=1000000000,last=-1,val;
    while(lw<=hi)
    {
        remaining--;
        int mid=(lw+hi)/2;
        printf("> %d\n",mid);
        fflush(stdout);
        scanf("%d",&val);
        if(val)
        {
            last=mid;
            lw=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return last;
}

int main()
{
    srand(time(0));
    scanf("%d",&N);
    if(N<=60)
    {
        for(int i=1;i<=N;i++)
        {
            printf("? %d\n",i);
            fflush(stdout);
            scanf("%d",&v[i]);
        }
        sort(v+1,v+1+N);
        printf("! %d %d\n",v[1],v[2]-v[1]);
        fflush(stdout);
    }
    else
    {
        Max=binsearch()+1;
        int a,b;
        printf("? 1\n");
        fflush(stdout);
        scanf("%d",&a);
        printf("? 2\n");
        fflush(stdout);
        scanf("%d",&b);
        if(a==b)
        {
            printf("! %d 0\n",Max);
            fflush(stdout);
            return 0;
        }
        for(int i=1;i<=remaining-2;i++)
        {
            printf("? %d\n",1+rand()%N);
            fflush(stdout);
            scanf("%d",&v[i]);
            if(v[i]==Max&&v[i]!=-1)
                continue;
            if(r==-1)
                r=Max-v[i];
            else
                r=gcd(r,Max-v[i]);
        }
        printf("! %d %d\n",Max-(N-1)*r,r);
        fflush(stdout);
    }
    return 0;
}


#include <bits/stdc++.h>

#define MaxN 100
#define INF 2140000000LL

using namespace std;

int Max,r=-1,Min,N,v[MaxN],remaining=60;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    else return gcd(b,a%b);
}

int binsearch()
{
    int lw=0,hi=1000000000,last=-1,val;
    while(lw<=hi)
    {
        remaining--;
        int mid=(lw+hi)/2;
        printf("> %d\n",mid);
        fflush(stdout);
        scanf("%d",&val);
        if(val)
        {
            last=mid;
            lw=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return last;
}

int main()
{
    srand(123456);
    scanf("%d",&N);
    if(N<=60)
    {
        for(int i=1;i<=N;i++)
        {
            printf("? %d\n",i);
            fflush(stdout);
            scanf("%d",&v[i]);
        }
        sort(v+1,v+1+N);
        printf("! %d %d\n",v[1],v[2]-v[1]);
        fflush(stdout);
    }
    else
    {
        Max=binsearch()+1;
        int a,b;
        printf("? 1\n");
        fflush(stdout);
        scanf("%d",&a);
        printf("? 2\n");
        fflush(stdout);
        scanf("%d",&b);
        if(a==b)
        {
            printf("! %d 0\n",Max);
            fflush(stdout);
            return 0;
        }
        for(int i=1;i<=remaining-2;i++)
        {
            printf("? %d\n",1+(5+rand())%N);
            fflush(stdout);
            scanf("%d",&v[i]);
            if(v[i]==Max&&v[i]!=-1)
                continue;
            if(r==-1)
                r=Max-v[i];
            else
                r=gcd(r,Max-v[i]);
        }
        printf("! %d %d\n",Max-(N-1)*r,r);
        fflush(stdout);
    }
    return 0;
}


#include <bits/stdc++.h>

#define MaxN 100
#define INF 2140000000LL

using namespace std;

int Max,r=-1,Min,N,v[MaxN],remaining=60;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    else return gcd(b,a%b);
}

int binsearch()
{
    int lw=0,hi=1000000000,last=-1,val;
    while(lw<=hi)
    {
        remaining--;
        int mid=(lw+hi)/2;
        printf("> %d\n",mid);
        fflush(stdout);
        scanf("%d",&val);
        if(val)
        {
            last=mid;
            lw=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return last;
}

int main()
{
    srand(123456);
    scanf("%d",&N);
    if(N<=60)
    {
        for(int i=1;i<=N;i++)
        {
            printf("? %d\n",i);
            fflush(stdout);
            scanf("%d",&v[i]);
        }
        sort(v+1,v+1+N);
        printf("! %d %d\n",v[1],v[2]-v[1]);
        fflush(stdout);
    }
    else
    {
        Max=binsearch()+1;
        int a,b;
        printf("? 1\n");
        fflush(stdout);
        scanf("%d",&a);
        printf("? 2\n");
        fflush(stdout);
        scanf("%d",&b);
        if(a==b)
        {
            printf("! %d 0\n",Max);
            fflush(stdout);
            return 0;
        }
        v[1]=Max;
        for(int i=2;i<remaining;i++)
        {
            printf("? %d\n",1+rand()%N);
            fflush(stdout);
            scanf("%d",&v[i]);
            for(int j=1;j<i;j++)
            {
                if(v[i]==v[j]||v[i]!=-1)
                    continue;
                if(r==-1)
                    r=abs(v[j]-v[i]);
            else
                r=gcd(r,abs(v[j]-v[i]));
            }
        }
        printf("! %d %d\n",Max-(N-1)*r,r);
        fflush(stdout);
    }
    return 0;
}


#include <bits/stdc++.h>

#define MaxN 100
#define INF 2140000000LL

using namespace std;

int Max,r=-1,Min,N,v[MaxN],remaining=60;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    else return gcd(b,a%b);
}

int binsearch()
{
    int lw=0,hi=1000000000,last=-1,val;
    while(lw<=hi)
    {
        remaining--;
        int mid=(lw+hi)/2;
        printf("> %d\n",mid);
        fflush(stdout);
        scanf("%d",&val);
        if(val)
        {
            last=mid;
            lw=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return last;
}

int main()
{
    srand(time(0));
    scanf("%d",&N);
    if(N<=60)
    {
        for(int i=1;i<=N;i++)
        {
            printf("? %d\n",i);
            fflush(stdout);
            scanf("%d",&v[i]);
        }
        sort(v+1,v+1+N);
        printf("! %d %d\n",v[1],v[2]-v[1]);
        fflush(stdout);
    }
    else
    {
        Max=binsearch()+1;
        int a,b;
        printf("? 1\n");
        fflush(stdout);
        scanf("%d",&a);
        printf("? 2\n");
        fflush(stdout);
        scanf("%d",&b);
        if(a==b)
        {
            printf("! %d 0\n",Max);
            return 0;
        }
        for(int i=1;i<=remaining-2;i++)
        {
            printf("? %d\n",1+rand()%N);
            fflush(stdout);
            scanf("%d",&v[i]);
            if(v[i]==Max&&v[i]!=-1)
                continue;
            if(r==-1)
                r=Max-v[i];
            else
                r=gcd(r,Max-v[i]);
        }
        printf("! %d %d\n",Max-N*r,r);
        fflush(stdout);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	const int mod = 2333;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(19970104);
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=1ll*rand()*mod%n+1;
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];
	typedef uniform_int_distribution<int> ui;
	mt19937 rd(chrono::system_clock::now().time_since_epoch().count());

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		n=read();
		solve();
		ui p(1,n);
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=p(rd);
			while(vis[tmp]) tmp=p(rd);
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt)l=mid+1;
			else r=mid-1,opt=mid;
		}
	}

	void work()
	{
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=30;i++)
		{
			for(int j=i+1;j<=30;j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(time(0));
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=((rand()<<15)|rand())%n+1;
			while(vis[tmp]) tmp=((rand()<<15)|rand())%n+1;
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(time(0));
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			vis[tmp]=true;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=30;i++)
		{
			for(int j=i+1;j<=30;j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(19950523);
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=30;i++)
		{
			for(int j=i+1;j<=30;j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(time(0));
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=30;i++)
		{
			for(int j=i+1;j<=30;j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(19950523);
		n=read();cnt=n;
		solve();
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=rand()%n+1;
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 1e6+5;
	const int mod = 2333;
	int ans=0,n,l,r,mid,lst,fst,opt,cnt;
	int a[100];
	bool vis[maxn];

	void solve()
	{
		l=0;r=1e9;
		while(l<=r)
		{
			mid=(l+r)>>1;
			cout<<'>'<<" "<<mid<<endl;
			cin>>opt;
			if(opt) l=mid+1;
			else r=mid-1,lst=mid;
		}
	}

	void work()
	{
		srand(19950523);
		n=read();
		solve();
		for(int i=1;i<=30;i++)
		{
			if(cnt==n) break;
			int tmp=rand()%n+1;
			while(vis[tmp]) tmp=1ll*rand()*mod%n+1;
			vis[tmp]=true;cnt++;
			cout<<'?'<<" "<<tmp<<endl;
			cin>>a[i];
		}
		for(int i=1;i<=min(30,n);i++)
		{
			for(int j=i+1;j<=min(30,n);j++)
			{
				ans=__gcd(ans,abs(a[j]-a[i]));
			}
		}
		fst=lst-(n-1)*ans;
		cout<<'!'<<" "<<fst<<" "<<ans<<endl;
	}

}

int main()
{
	zzc::work();
	return 0;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    for(int i = 0; i < 30; i++)
    {
        arr.push_back(get_ai(i+1));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < 30; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    if(x > 1e9) return false;
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    int bogo = 40;
    cin >> n;
    default_random_engine gen;
    uniform_int_distribution<int> dis(1, n);
    auto myrand = bind(dis, gen);
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = myrand();
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    int bogo = 45;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    for(int i = 0; i < bogo; i++)
    {
        arr.push_back(get_ai(i+1));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+9487+time(NULL));
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = rand()%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+time(NULL));
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = rand()%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+87+time(NULL));
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = rand()%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    int bogo = 40;
    cin >> n;
    default_random_engine gen;
    uniform_int_distribution<int> dis(1, n);
    auto myrand = bind(dis, gen);
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = myrand();
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+87+time(NULL));
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = (rand()+rand()+rand()+rand())%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    d = abs(arr[1]-arr[0]);
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(abs(arr[i]-arr[i-1]), d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    for(int i = 0; i < bogo; i++)
    {
        arr.push_back(get_ai(i+1));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+time(NULL));
    int bogo = 41;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = rand()%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    srand(7122+time(NULL));
    int bogo = 40;
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    vector<bool> qed(n+1, false);
    for(int i = 0; i < bogo; i++)
    {
        int idx = rand()%n;
        while(qed[idx]) idx = rand()%n;
        qed[idx] = true;
        arr.push_back(get_ai(idx));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < bogo; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


//
#include <bits/stdc++.h>

#define int ll
using namespace std;
typedef long long ll;

int n;
vector<ll> arr;
ll d;

void init();
void process();

int32_t main()
{
    init();
    process();
    return 0;
}

ll get_ai(int i)
{
    cout << "? " << i << endl;
    cout.flush();
    ll a; cin >> a; return a;
}

bool check_x(ll x)
{
    cout << "> " << x << endl;
    cout.flush();
    bool arr; cin >> arr; return arr;
}

void init()
{
    cin >> n;
    if(n <= 60)
    {
        for(int i = 0; i < n; i++) arr.push_back(get_ai(i+1));
        sort(arr.begin(), arr.end());
        cout << "! " << arr[0] << " " << arr[1]-arr[0] << endl;
        exit(0);
    }
    for(int i = 0; i < 30; i++)
    {
        arr.push_back(get_ai(i+1));
    }
    sort(arr.begin(), arr.end());
    d = arr[1]-arr[0];
    for(int i = 2; i < 30; i++)
    {
        d = __gcd(arr[i]-arr[i-1], d);
    }
}

void process()
{
    ll low = 0, high = n-1, mid, big = arr.back();
    while(low <= high)
    {
        mid = (low+high)/2;
        if(check_x(arr.back()+d*mid) == 1)
        {
            big = arr.back()+d*mid+d;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }
    // big = a1 * d(n-1)
    ll a1 = big-d*(n-1);
    cout << "! " << a1 << " " << d << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(43);
    int g = 0;
    for (int i = 1; i <= 30; i++) {
        int x = rand() * rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int y = get(x - 1);
    printf("! %d %d\n", x - (x - y) * (n - 1), x - y);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(43);
    int g = 0;
    for (int i = 1; i <= 30; i++) {
        int x = rand() * rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        if (t ^ y) g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int y = get(x - 1);
    printf("! %d %d\n", x - (x - y) * (n - 1), y - x);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(time(0));
    int g = 0;
    for (int i = 1; i < 10; i++) {
        int x = rand() * rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int y = get(x - 1);
    printf("! %d %d\n", x, y - x);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int x) {
    srand(19260817);
    int g = 0;
    for (int i = 1; i <= 30; i++) {
        int x = rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        g = __gcd(g, y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int x) {
    srand(19260817);
    int g = 0;
    for (int i = 1; i <= 30; i++) {
        int x = rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        g = __gcd(g, x - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(19260817);
    int g = 0;
    for (int i = 1; i < 10; i++) {
        int x = rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int y = get(x - 1);
    printf("! %d %d\n", x - (y - x) * (n - 1), y - x);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(time(0));
    int g = 0;
    for (int i = 1; i < 30; i++) {
        int x = rand() * rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int x) {
    srand(19260817);
    int g = 0;
    for (int i = 1; i < 30; i++) {
        int x = rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, x - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(43);
    int g = 0;
    for (int i = 1; i <= 30; i++) {
        int x = rand() * rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        if (t ^ y) g = __gcd(g, t - y);
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9 + 1);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, a[maxn];

bool ask(int x) {
    printf("> %d\n", x);
    fflush(stdout);
    int b;
    scanf("%d", &b);
    assert(~b);
    return b;
}

int get(int lower) {
    int l = 0, r = lower - 1, ans;
    while (l <= r) {
        int mid = (l + r) >> 1;
        ask(mid) ? l = mid + 1 : r = (ans = mid) - 1;
    }
    return ans;
}

int solve(int t) {
    srand(19260817);
    int g = 0;
    for (int i = 1; i < 10; i++) {
        int x = rand() % n + 1;
        printf("? %d\n", x);
        fflush(stdout);
        int y;
        scanf("%d", &y);
        assert(~y);
        g = __gcd(g, t - y);
        cout << g << endl;
    }
    return g;
}

int main() {
    scanf("%d", &n);
    int x = get(1e9);
    int d = solve(x);
    printf("! %d %d\n", x - d * (n - 1), d);
    fflush(stdout);
    return 0;
}


#pragma optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

ll get_seed(string s)
{
    ll ans = 0;
    for (int i = 0; i < s.size(); ++i)
        ans += s[i];
    return ans;
}

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

// debug defines
#ifdef HOME
    int jjj;
    #define PO cout << "Pomelo" << endl;
    #define OL cout << "Oliva" << endl;
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) cout << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
    #define debug_vp(x) cout << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl;
    #define wait() cin >> jjj;
#else
    #define PO 0
    #define OL 0
    #define debug(x) 0
    #define debug_p(x) 0
    #define debug_vp(x) 0
    #define debug_v(x) 0
    #define debug_vp(x) 0
    #define wait() 0
#endif // HOME
// end of debug defines

int find_ma()
{
    int l = 0, r = 1e9 + 1;
    while (r - l > 1)
    {
        int m = (r + l) / 2;
        cout << "> " << m << endl;
        int t;
        cin >> t;
        if (t == 0)
            r = m;
        else
            l = m;
    }
    return r;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
   // ios_base::sync_with_stdio(0);
   // cout.tie(0);
   // cin.tie(0);

    int n;
    cin >> n;
    int ma = find_ma();
    vector<int> arr;
    vector<bool> was(n);

    mt19937 mt(time(0));
    mt();
    mt();
    mt();
    debug(ma);
    int tt = 0;
    for (int i = 0; i < min(28, n); ++i)
    {
        int j = mt() % n;
        while (was[j] && tt < 1000)
        {
            j = mt() % n;
            ++tt;
        }
        tt = 0;
        if (was[j])
            for (int k = 0; k < 100; ++k)
                if (!was[k])
                {
                    j = k;
                    break;
                }
        was[j] = 1;
        cout << "? " << j + 1 << endl;
        int t;
        cin >> t;
        arr.push_back(t);
    }
    ll g = 0;
    debug_v(arr);
    for (int i = 0; i < arr.size(); ++i)
        for (int j = 0; j < arr.size(); ++j){
            if (i != j)
                g = gcd(g, abs(arr[i] - arr[j]));
        }

    ll can = 0;
    for (int i = 1; i * i < g; ++i)
    {
        if (ma - g / i * (n - 1) >= 0)
        {
            g /= i;
            break;
        }
        if (ma - i * (n - i) >= 0)
            can = i;
    }
    g = max(g, can);
    if (ma - g * (n - 1) < 0)
        g = can;

    cout << "! " << ma - g * (n - 1) << " " << g << endl;

    return 0;
}


#pragma optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

ll get_seed(string s)
{
    ll ans = 0;
    for (int i = 0; i < s.size(); ++i)
        ans += s[i];
    return ans;
}

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

// debug defines
#ifdef HOME
    int jjj;
    #define PO cout << "Pomelo" << endl;
    #define OL cout << "Oliva" << endl;
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) cout << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
    #define debug_vp(x) cout << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl;
    #define wait() cin >> jjj;
#else
    #define PO 0
    #define OL 0
    #define debug(x) 0
    #define debug_p(x) 0
    #define debug_vp(x) 0
    #define debug_v(x) 0
    #define debug_vp(x) 0
    #define wait() 0
#endif // HOME
// end of debug defines

int find_ma()
{
    int l = 0, r = 1e9 + 1;
    while (r - l > 1)
    {
        int m = (r + l) / 2;
        cout << "> " << m << endl;
        int t;
        cin >> t;
        if (t == 0)
            r = m;
        else
            l = m;
    }
    return l;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
   // ios_base::sync_with_stdio(0);
   // cout.tie(0);
   // cin.tie(0);

    int n;
    cin >> n;
    int ma = find_ma();
    vector<int> arr;
    vector<bool> was(n);

    mt19937 mt(get_seed("LANA01"));
    mt();
    mt();
    mt();

    int t;
    for (int i = 0; i < min(30, n); ++i)
    {
        int j = mt() % n;
        while (was[j] && t < 1000)
        {
            j = mt() % n;
            ++t;
        }
        for (int k = 0; k < 100; ++k)
            if (!was[k])
        {
            j = k;
            break;
        }
        cout << "? " << j + 1 << endl;
        int t;
        cin >> t;
        arr.push_back(t);
    }
    ll g = 0;
    for (int i = 0; i < arr.size(); ++i)
        for (int j = 0; j < arr.size(); ++j){
            if (i != j)
                g = gcd(g, abs(arr[i] - arr[j]));
        }

    cout << "! " << ma - g * n << " " << g << endl;

    return 0;
}


#pragma optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

ll get_seed(string s)
{
    ll ans = 0;
    for (int i = 0; i < s.size(); ++i)
        ans += s[i];
    return ans;
}

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

// debug defines
#ifdef HOME
    int jjj;
    #define PO cout << "Pomelo" << endl;
    #define OL cout << "Oliva" << endl;
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) cout << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
    #define debug_vp(x) cout << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl;
    #define wait() cin >> jjj;
#else
    #define PO 0
    #define OL 0
    #define debug(x) 0
    #define debug_p(x) 0
    #define debug_vp(x) 0
    #define debug_v(x) 0
    #define debug_vp(x) 0
    #define wait() 0
#endif // HOME
// end of debug defines

int find_ma()
{
    int l = 0, r = 1e9 + 1;
    while (r - l > 1)
    {
        int m = (r + l) / 2;
        cout << "> " << m << endl;
        int t;
        cin >> t;
        if (t == 0)
            r = m;
        else
            l = m;
    }
    return r;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
   // ios_base::sync_with_stdio(0);
   // cout.tie(0);
   // cin.tie(0);

    int n;
    cin >> n;
    int ma = find_ma();
    vector<int> arr;
    vector<bool> was(n);

    mt19937 mt(get_seed("SvetkaKonfetka"));
    mt();
    mt();
    mt();
    debug(ma);
    int t;
    for (int i = 0; i < min(30, n); ++i)
    {
        int j = mt() % n;
        while (was[j] && t < 1000)
        {
            j = mt() % n;
            ++t;
        }
        for (int k = 0; k < 100; ++k)
            if (!was[k])
        {
            j = k;
            break;
        }
        was[j] = 1;
        cout << "? " << j + 1 << endl;
        int t;
        cin >> t;
        arr.push_back(t);
    }
    ll g = 0;
    debug_v(arr);
    for (int i = 0; i < arr.size(); ++i)
        for (int j = 0; j < arr.size(); ++j){
            if (i != j)
                g = gcd(g, abs(arr[i] - arr[j]));
        }

    ll can = 0;
    for (int i = 1; i * i < g; ++i)
    {
        if (ma - g / i * (n - 1) >= 0)
        {
            g /= i;
            break;
        }
        if (ma - i * (n - i) >= 0)
            can = i;
    }
    g = max(g, can);
    if (ma - g * (n - 1) < 0)
        g = can;

    cout << "! " << ma - g * (n - 1) << " " << g << endl;

    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
ll sum_up = 0, sum_down = 0;

int get_ans() {
    ll ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return max((ll)n, ans);
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 1; i <= l + 1; i++) {
                del(i);
            }
            for (int i = r - 1; i <= r + 1; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            for (int i = l - 1; i <= l + 1; i++) {
                check(i);
            }
            for (int i = r - 1; i <= r + 1; i++) {
                check(i);
            }
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
int sum_up = 0, sum_down = 0;

int get_ans() {
    int ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return max(n, ans);
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 2; i <= l + 2; i++) {
                del(i);
            }
            for (int i = r - 2; i <= r + 2; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            for (int i = l - 2; i <= l + 2; i++) {
                check(i);
            }
            for (int i = r - 2; i <= r + 2; i++) {
                check(i);
            }
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
int sum_up = 0, sum_down = 0;

int get_ans() {
    int ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 2; i <= l + 2; i++) {
                del(i);
            }
            for (int i = r - 2; i <= r + 2; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            for (int i = l - 2; i <= l + 2; i++) {
                check(i);
            }
            for (int i = r - 2; i <= r + 2; i++) {
                check(i);
            }
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
ll sum_up = 0, sum_down = 0;

int get_ans() {
    if (n == 1) {
        return a[0];
    }
    ll ans = sum_up - sum_down;
    if (up.size() > 0 && down.size() > 0 && *up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (up.size() > 0 && down.size() > 0 && *--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
                del(l);
                del(l + 1);
                del(l - 1);
                del(r);
                del(r + 1);
                del(r - 1);
            swap(a[l], a[r]);
                check(l);
                check(l + 1);
                check(l - 1);
                check(r);
                check(r + 1);
                check(r - 1);
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
ll sum_up = 0, sum_down = 0;

int get_ans() {
    ll ans = sum_up - sum_down;
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        sum_up += a[i];
    }
    if (i != 0 && i != n - 1 && a[i - 1] > a[i] && a[i] < a[i + 1]) {
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        sum_up -= a[i];
    }
    if (i != 0 && i != n - 1 && a[i - 1] > a[i] && a[i] < a[i + 1]) {
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 1; i <= l + 1; i++) {
                del(i);
            }
            for (int i = max(r - 1, l + 2); i <= r + 1; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            for (int i = l - 1; i <= l + 1; i++) {
                check(i);
            }
            for (int i = max(r - 1, l + 2); i <= r + 1; i++) {
                check(i);
            }
            cout << get_ans() << "\n";

        }
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
int sum_up = 0, sum_down = 0;

int get_ans() {
    int ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end()) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end()) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
            /*cout << "up ";
            for (int elem : up) {
                cout << elem << ' ';
            }
            cout << "\ndown ";
            for (int elem : down) {
                cout << elem << ' ';
            }
            cout << "\n";
            cout << sum_up << ' ' << sum_down << "\n";*/
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 1; i <= l + 1; i++) {
                del(i);
            }
            for (int i = r - 1; i <= r + 1; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            //sum_up -= a[l];

            for (int i = l - 1; i <= l + 1; i++) {
                check(i);
            }
            for (int i = r - 1; i <= r + 1; i++) {
                check(i);
            }
            cout << get_ans() << "\n";
            /*cout << "up ";
            for (int elem : up) {
                cout << elem << ' ';
            }
            cout << "\ndown ";
            for (int elem : down) {
                cout << elem << ' ';
            }
            cout << "\n";
            cout << sum_up << ' ' << sum_down << "\n";*/

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
ll sum_up = 0, sum_down = 0;

int get_ans() {
    ll ans = sum_up - sum_down;
    if (up.size() > 0 && down.size() > 0 && *up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (up.size() > 0 && down.size() > 0 && *--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return max((ll)n, ans);
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
                del(l);
                del(l + 1);
                del(l - 1);
                del(r);
                del(r + 1);
                del(r - 1);
            swap(a[l], a[r]);
                check(l);
                check(l + 1);
                check(l - 1);
                check(r);
                check(r + 1);
                check(r - 1);
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
int sum_up = 0, sum_down = 0;

int get_ans() {
    int ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return ans;
}

void check(int i) {
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if ((i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.erase(i);
        sum_up -= a[i];
    }
    if ((i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            del(l);
            del(r);
            swap(a[l], a[r]);
            //sum_up -= a[l];

            check(l);
            check(r);
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
set<int> up, down;
int sum_up = 0, sum_down = 0;

int get_ans() {
    int ans = sum_up - sum_down;
    if (*up.begin() > *down.begin()) {
        ans += a[*down.begin()];
    }
    if (*--up.end() < *--down.end()) {
        ans += a[*--down.end()];
    }
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) == up.end() && (i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        up.insert(i);
        sum_up += a[i];
    }
    if (down.find(i) == down.end() && (i == 0 || a[i - 1] > a[i]) && (i == n - 1 || a[i] < a[i + 1])) {
        down.insert(i);
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if (up.find(i) != up.end()) {
        up.erase(i);
        sum_up -= a[i];
    }
    if (down.find(i) != down.end()) {
        down.erase(i);
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = 0; i < n; i++) {
                del(i);
            }
            /*for (int i = 0; i <= r + 1; i++) {
                del(i);
            }*/
            swap(a[l], a[r]);
            for (int i = 0; i < n; i++) {
                check(i);
            }
            /*for (int i = r - 1; i <= r + 1; i++) {
                check(i);
            }*/
            cout << get_ans() << "\n";

        }
        up = {};
        down = {};
        sum_up = 0;
        sum_down = 0;
    }
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 2e5 + 10;
const long double EPS = 1e-9;
int n, q;
vector<int> a;
ll sum_up = 0, sum_down = 0;

int get_ans() {
    ll ans = sum_up - sum_down;
    return ans;
}

void check(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        sum_up += a[i];
    }
    if (i != 0 && i != n - 1 && a[i - 1] > a[i] && a[i] < a[i + 1]) {
        sum_down += a[i];
    }
}

void del(int i) {
    if (i < 0 || i >= n) {
        return;
    }
    if ((i == 0 || a[i - 1] < a[i]) && (i == n - 1 || a[i] > a[i + 1])) {
        sum_up -= a[i];
    }
    if (i != 0 && i != n - 1 && a[i - 1] > a[i] && a[i] < a[i + 1]) {
        sum_down -= a[i];
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> q;
        a = vector<int> (n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            check(i);
        }
        cout << get_ans() << "\n";
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            for (int i = l - 1; i <= l + 1; i++) {
                del(i);
            }
            for (int i = max(r - 1, l + 2); i <= r + 1; i++) {
                del(i);
            }
            swap(a[l], a[r]);
            for (int i = l - 1; i <= l + 1; i++) {
                check(i);
            }
            for (int i = max(r - 1, l + 2); i <= r + 1; i++) {
                check(i);
            }
            cout << get_ans() << "\n";

        }
        sum_up = 0;
        sum_down = 0;
        //cout << "====\n";
    }
    return 0;
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        // input(a, 1, n);
        for (int i = 1; i <= n; ++i) cin >> a[i];
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            // input(l, r);
            cin >> l >> r;
            set<int> s{l - 1, l, l + 1, r - 1, r, r + 1};
            for (int i : s) update(i, 1);
            swap(a[l], a[r]);
            for (int i : s) update(i, -1);
            // print(ans);
            // assert(max(l - 1, 1) + 6 >= min(r + 1, n));
            cout << ans << '\n';
        }
    }
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        // input(a, 1, n);
        for (int i = 1; i <= n; ++i) cin >> a[i];
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            input(l, r);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, 1);
            swap(a[l], a[r]);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, -1);
            // print(ans);
            cout << ans << '\n';
        }
    }
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        // input(a, 1, n);
        for (int i = 1; i <= n; ++i) cin >> a[i];
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            // input(l, r);
            cin >> l >> r;
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, 1);
            swap(a[l], a[r]);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, -1);
            // print(ans);
            assert(max(l - 1, 1) + 6 >= min(r + 1, n));
            cout << ans << '\n';
        }
    }
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        // input(a, 1, n);
        for (int i = 1; i <= n; ++i) cin >> a[i];
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            // input(l, r);
            cin >> l >> r;
            set<int> s{l - 1, l, l + 1, r - 1, r, r + 1};
            for (int i : s) update(i, 1);
            swap(a[l], a[r]);
            for (int i : s) update(i, -1);
            // print(ans);
            assert(max(l - 1, 1) + 6 >= min(r + 1, n));
            cout << ans << '\n';
        }
    }
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        // input(a, 1, n);
        for (int i = 1; i <= n; ++i) cin >> a[i];
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            // input(l, r);
            cin >> l >> r;
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, 1);
            swap(a[l], a[r]);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, -1);
            // print(ans);
            cout << ans << '\n';
        }
    }
}


/*
3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3

*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 3e5 + 5, M = 1000000007, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << "\033[31m" << a[i] << "\033[0m" << " \n"[i == (int)a.size() - 1]; }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); } template <typename T> void print(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i == (int)a.size() - 1]; }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T> a) { for (auto&& x : a) input(a); }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; } ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % M; a = a * a % M, b >>= 1; } return ret; } ll pinv(ll x, ll mod = M) { return qpow(x, mod - 2); }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
int a[N];
void Main() {
    int T;
    input(T);
    while (T--) {
        int n, q;
        input(n, q);
        input(a, 1, n);
        a[0] = a[n + 1] = -1;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans += a[i];
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans -= a[i];
        }
        print(ans);
        auto update = [&ans](int i, int x) {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) ans -= a[i] * x;
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) ans += a[i] * x;
        };
        while (q--) {
            int l, r;
            input(l, r);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, 1);
            swap(a[l], a[r]);
            for (int i = max(l - 1, 1); i <= min(r + 1, n); ++i) update(i, -1);
            print(ans);
        }
    }
}