#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
ll n,p[nmax],f,c,tot,ca,bl,ok,v[nmax],i,j;
ll ml,x,rs;
vector<ll>pr,m[nmax];
int qry(int tp,int a)
{
    if(!tp)cout<<"A ";
    else cout<<"B ";
    assert(a<=n);
    cout<<a<<endl;
    int b;
    cin>>b;
    return b;
}
void ans(int x)
{
    cout<<"C "<<x<<endl;
    assert(x<=n);
    exit(0);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=2;i<=n;i++)
    {
        if(p[i])continue;
        for(j=i;j<=n;j+=i)
        {
            if(!p[j])p[j]=i;
            m[i].pb(j);
        }
    }
    for(i=2;i<=n;i++)if(p[i]==i)pr.pb(i);
    for(i=1;i<=n;i++)v[i]=1;
    bl=1,rs=1,ok=min(lun(pr),50),tot=n,f=-1;
    for(i=0;i<lun(pr);i++)
    {
        if(bl && (i+1)%ok==0 && qry(0,1)!=tot)
        {
            bl=0;
            f=i-1;
        }
        x=pr[i],c=0;
        for(j=0;j<lun(m[x]);j++)
        {
            c+=v[m[x][j]];
            tot-=v[m[x][j]];
            v[m[x][j]]=0;
        }
        ca=qry(1,x);
        if(ca!=c)
        {
            ml=x*x;
            while(ml<=n && qry(0,ml))ml*=x;
            ml/=x;
            rs*=ml;
        }
    }
    if(qry(0,1)==1)ans(1);
    if(f==-1)f=lun(pr)-1;
    for(;f>=0;f--)
    {
        x=pr[f];
        if(qry(0,x))
        {
            ml=x*x;
            while(ml<=n && qry(0,ml))ml*=x;
            ml/=x;
            rs*=ml;
            ans(rs);
        }
    }
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
int n,p[nmax],ml,x,f,rs,c,tot,ca,bl,ok,v[nmax],i,j;
vector<int>pr,m[nmax];
int qry(int tp,int a)
{
    if(!tp)cout<<"A ";
    else cout<<"B ";
    cout<<a<<endl;
    int b;
    cin>>b;
    return b;
}
void ans(int x)
{
    cout<<"C "<<x<<endl;
    exit(0);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=2;i<=n;i++)
    {
        if(p[i])continue;
        for(j=i;j<=n;j+=i)
        {
            if(!p[j])p[j]=i;
            m[i].pb(j);
        }
    }
    for(i=2;i<=n;i++)if(p[i]==i)pr.pb(i);
    for(i=1;i<=n;i++)v[i]=1;
    bl=1,rs=1,ok=min(lun(pr),50),tot=n,f=-1;
    for(i=0;i<lun(pr);i++)
    {
        if(bl && (i+1)%ok==0 && qry(0,1)!=tot)
        {
            bl=0;
            f=i-1;
        }
        x=pr[i],c=0;
        for(j=0;j<lun(m[x]);j++)
        {
            c+=v[m[x][j]];
            tot-=v[m[x][j]];
            v[m[x][j]]=0;
        }
        ca=qry(1,x);
        if(ca!=c)
        {
            ml=x*x;
            while(ml<=n && qry(0,ml))ml*=x;
            ml/=x;
            rs*=ml;
        }
    }
    if(qry(0,1)==1)ans(1);
    for(;f>=0;f--)
    {
        x=pr[f];
        if(qry(0,x))
        {
            ml=x*x;
            while(ml<=n && qry(0,ml))ml*=x;
            ml/=x;
            rs*=ml;
            ans(ml);
        }
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define K 400

vector<int> choto, boro;
bool sv[M];

int queryA(int x)
{
    printf("A %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

int queryB(int x)
{
    printf("B %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

void queryC(int x)
{
    printf("C %d\n", x);
    fflush(stdout);
}

int main()
{
    for(int i = 2; i < M; i++)
    {
        for(int j = i+i; j < M; j += i) sv[j] = true;
    }

    for(int i = 2; i < M; i++)
    {
        if(sv[i] == false)
        {
            if(i < K) choto.push_back(i);
            else boro.push_back(i);
        }
    }

    int n;
    scanf("%d", &n);

    int ans = 1;
    for(int p: choto)
    {
        if(p > n) break;

        queryB(p);

        int m = p;
        while(m <= n && queryB(m) == 1) m *= p;

        ans *= m/p;
    }

    int ase = queryA(1);

    int i = 0;
    bool paise = false;

    while(i < boro.size() && boro[i] <= n)
    {
        vector<int> tmp;
        for(int j = i; j < min((int)boro.size(), i+100) && boro[j] <= n; j++)
        {
            tmp.push_back(boro[j]);
            queryB(boro[j]);
        }

        if(queryA(1) != ase-tmp.size())
        {
            for(int p: tmp)
            {
                if(queryA(p) == 1)
                {
                    ans *= p;
                    paise = true;

                    break;
                }
            }
        }

        if(paise) break;
        else ase -= tmp.size();

        i += tmp.size();
    }

    queryC(ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define K 400

vector<int> choto, boro;
bool sv[M];

int queryA(int x)
{
    printf("A %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

int queryB(int x)
{
    printf("B %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

void queryC(int x)
{
    printf("C %d\n", x);
    fflush(stdout);

    exit(0);
}

int main()
{
    int tot = 0;

    for(int i = 2; i < M; i++)
    {
        for(int j = i+i; j < M; j += i) sv[j] = true;
    }

    for(int i = 2; i < M; i++)
    {
        if(sv[i] == false)
        {
            if(i < K) choto.push_back(i);
            else boro.push_back(i);
        }
    }

    int n;
    scanf("%d", &n);

    int ans = 1;
    for(int p: choto)
    {
        if(p > n) break;

        queryB(p);

        int m = p;
        while(m <= n && queryB(m) == 1) m *= p;

        ans *= m/p;
    }

    int ase = queryA(1);

    int i = 0;
    bool paise = false;

    while(i < boro.size() && boro[i] <= n)
    {
        vector<int> tmp;
        for(int j = i; j < min((int)boro.size(), i+100) && boro[j] <= n; j++)
        {
            tmp.push_back(boro[j]);
            if(queryB(boro[j]) == 2) queryC(boro[j]*ans);
        }

        if(queryA(1) != ase-tmp.size())
        {
            for(int p: tmp)
            {
                if(queryA(p) == 1)
                {
                    ans = p;
                    paise = true;

                    break;
                }
            }
        }

        if(paise) break;
        else ase -= tmp.size();

        i += tmp.size();
    }

    queryC(ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define K 400

vector<int> choto, boro;
bool sv[M];

int queryA(int x)
{
    printf("A %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

int queryB(int x)
{
    printf("B %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

void queryC(int x)
{
    printf("C %d\n", x);
    fflush(stdout);
}

int main()
{
    int tot = 0;

    for(int i = 2; i < M; i++)
    {
        for(int j = i+i; j < M; j += i) sv[j] = true;
    }

    for(int i = 2; i < M; i++)
    {
        if(sv[i] == false)
        {
            if(i < K) choto.push_back(i);
            else boro.push_back(i);
        }
    }

    int n;
    scanf("%d", &n);

    int ans = 1;
    for(int p: choto)
    {
        if(p > n) break;

        queryB(p);

        int m = p;
        while(m <= n && queryB(m) == 1) m *= p;

        ans *= m/p;
    }

    int ase = queryA(1);

    int i = 0;
    bool paise = false;

    while(i < boro.size() && boro[i]*ans <= n)
    {
        vector<int> tmp;
        for(int j = i; j < min((int)boro.size(), i+100) && boro[j]*ans <= n; j++)
        {
            tmp.push_back(boro[j]*ans);
            queryB(boro[j]*ans);
        }

        if(queryA(1) != ase-tmp.size())
        {
            for(int p: tmp)
            {
                if(queryA(p) == 1)
                {
                    ans = p;
                    paise = true;

                    break;
                }
            }
        }

        if(paise) break;
        else ase -= tmp.size();

        i += tmp.size();
    }

    queryC(ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define K 400

vector<int> choto, boro;
bool sv[M];

int queryA(int x)
{
    printf("A %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

int queryB(int x)
{
    printf("B %d\n", x);
    fflush(stdout);

    int y;
    scanf("%d", &y);

    return y;
}

void queryC(int x)
{
    printf("C %d\n", x);
    fflush(stdout);
}

int main()
{
    for(int i = 2; i < M; i++)
    {
        for(int j = i+i; j < M; j += i) sv[j] = true;
    }

    for(int i = 2; i < M; i++)
    {
        if(sv[i] == false)
        {
            if(i < K) choto.push_back(i);
            else boro.push_back(i);
        }
    }

    int n;
    scanf("%d", &n);

    int ans = 1;
    for(int p: choto)
    {
        if(p > n) break;

        queryB(p);

        int m = p;
        while(m <= n && queryB(m) == 1) m *= p;

        ans *= m/p;
    }

    int ase = queryA(1);

    int i = 0;
    bool paise = false;

    while(i < boro.size() && boro[i] <= n)
    {
        vector<int> tmp;
        for(int j = i; j < min((int)boro.size(), i+100) && boro[j] <= n; j++)
        {
            tmp.push_back(boro[j]);
            queryB(j);
        }

        if(queryA(1) != ase-tmp.size())
        {
            for(int p: tmp)
            {
                if(queryA(p) == 1)
                {
                    ans *= p;
                    paise = true;

                    break;
                }
            }
        }

        if(paise) break;
        else ase -= tmp.size();

        i += tmp.size();
    }

    queryC(ans);

    return 0;
}


// Code by KSkun, 2020/9
#include <cmath>

#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int MAXN = 100005;

int n;
bool is_prime[MAXN];
vector<int> primes;

void sieve(int n) {
	fill(is_prime + 2, is_prime + n, true);
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) primes.push_back(i);
		for (auto p : primes) {
			if (p * i > n) break;
			is_prime[p * i] = false;
			if (i % p == 0) break;
		}
	}
}

bool vis[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	sieve(n);
	int left = n, ans = 1, sqrt_n = sqrt(n);
	bool min_prim_flag = false;
	for (int i = 0; i < primes.size(); i++) {
		int p = primes[i];
		cout << "B " << p << endl; cout.flush();
		int mul_cnt = 0, real_mul_cnt;
		cin >> real_mul_cnt;
		for (int i = p; i <= n; i += p) { // mark all multiples of i as deleted
			if (!vis[i]) {
				vis[i] = true; left--; mul_cnt++;
			}
		}
		if (mul_cnt != real_mul_cnt) { // p is a factor of x
			int res;
			for (int i = p; i <= n; i *= p) {
				cout << "A " << i << endl; cout.flush();
				cin >> res;
				if (res != 1) break;
				ans *= p;
			}
		}
		if (((i + 1) % sqrt_n == 0 || i == primes.size() - 1) && !min_prim_flag) { // divide into sqrt(n) blocks
			cout << "A 1" << endl; cout.flush();
			int res;
			cin >> res;
			if (res != left) { // min factor in this block
				for (int j = i - sqrt_n + 1; j <= i; j++) {
					cout << "A " << primes[j] << endl; cout.flush();
					cin >> res;
					if (res == 1) { // min factor
						for (int k = primes[j]; k <= n; k *= primes[j]) {
							cout << "A " << k << endl; cout.flush();
							cin >> res;
							if (res != 1) break;
							ans *= primes[j];
						}
						min_prim_flag = true;
						break;
					}
				}
			}
		}
	}
	cout << "C " << ans << endl; cout.flush();
	return 0;
}


// Code by KSkun, 2020/9
#include <cmath>

#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int MAXN = 100005;

int n;
bool is_prime[MAXN];
vector<int> primes;

void sieve(int n) {
	fill(is_prime + 2, is_prime + n + 1, true);
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) primes.push_back(i);
		for (auto p : primes) {
			if (p * i > n) break;
			is_prime[p * i] = false;
			if (i % p == 0) break;
		}
	}
}

bool vis[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	if (n == 1) {
		cout << "C 1" << endl; cout.flush();
		return 0;
	}
	sieve(n);
	int left = n, ans = 1, sqrt_n = sqrt(n);
	bool min_prim_flag = false;
	for (int i = 0; i < primes.size(); i++) {
		int p = primes[i];
		cout << "B " << p << endl; cout.flush();
		int mul_cnt = 0, real_mul_cnt;
		cin >> real_mul_cnt;
		for (int i = p; i <= n; i += p) { // mark all multiples of i as deleted
			if (!vis[i]) {
				vis[i] = true; left--; mul_cnt++;
			}
		}
		if (mul_cnt != real_mul_cnt) { // p is a factor of x
			int res;
			for (LL j = p; j <= n; j *= p) {
				cout << "A " << j << endl; cout.flush();
				cin >> res;
				if (res != 1) break;
				ans *= p;
			}
		}
		if (((i + 1) % sqrt_n == 0 || i == primes.size() - 1) && !min_prim_flag) { // divide into sqrt(n) blocks
			cout << "A 1" << endl; cout.flush();
			int res;
			cin >> res;
			if (res != left) { // min factor in this block
				for (int j = i - sqrt_n + 1; j <= i; j++) {
					cout << "A " << primes[j] << endl; cout.flush();
					cin >> res;
					if (res == 1) { // min factor
						for (LL k = primes[j]; k <= n; k *= primes[j]) {
							cout << "A " << k << endl; cout.flush();
							cin >> res;
							if (res != 1) break;
							ans *= primes[j];
						}
						min_prim_flag = true;
						break;
					}
				}
			}
		}
	}
	cout << "C " << ans << endl; cout.flush();
	return 0;
}


// Code by KSkun, 2020/9
#include <cmath>

#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int MAXN = 100005;

int n;
bool is_prime[MAXN];
vector<int> primes;

void sieve(int n) {
	fill(is_prime + 2, is_prime + n, true);
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) primes.push_back(i);
		for (auto p : primes) {
			if (p * i > n) break;
			is_prime[p * i] = false;
			if (i % p == 0) break;
		}
	}
}

bool vis[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	sieve(n);
	int left = n, ans = 1, sqrt_n = sqrt(n);
	bool min_prim_flag = false;
	for (int i = 0; i < primes.size(); i++) {
		int p = primes[i];
		cout << "B " << p << endl; cout.flush();
		int mul_cnt = 0, real_mul_cnt;
		cin >> real_mul_cnt;
		for (int i = p; i <= n; i += p) { // mark all multiples of i as deleted
			if (!vis[i]) {
				vis[i] = true; left--; mul_cnt++;
			}
		}
		if (mul_cnt != real_mul_cnt) { // p is a factor of x
			int res;
			for (LL j = p; j <= n; j *= p) {
				cout << "A " << j << endl; cout.flush();
				cin >> res;
				if (res != 1) break;
				ans *= p;
			}
		}
		if (((i + 1) % sqrt_n == 0 || i == primes.size() - 1) && !min_prim_flag) { // divide into sqrt(n) blocks
			cout << "A 1" << endl; cout.flush();
			int res;
			cin >> res;
			if (res != left) { // min factor in this block
				for (int j = i - sqrt_n + 1; j <= i; j++) {
					cout << "A " << primes[j] << endl; cout.flush();
					cin >> res;
					if (res == 1) { // min factor
						for (LL k = primes[j]; k <= n; k *= primes[j]) {
							cout << "A " << k << endl; cout.flush();
							cin >> res;
							if (res != 1) break;
							ans *= primes[j];
						}
						min_prim_flag = true;
						break;
					}
				}
			}
		}
	}
	cout << "C " << ans << endl; cout.flush();
	return 0;
}


// Code by KSkun, 2020/9
#include <cmath>

#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int MAXN = 100005;

int n;
bool is_prime[MAXN];
vector<int> primes;

void sieve(int n) {
	fill(is_prime + 2, is_prime + n, true);
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) primes.push_back(i);
		for (auto p : primes) {
			if (p * i > n) break;
			is_prime[p * i] = false;
			if (i % p == 0) break;
		}
	}
}

bool vis[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	if (n == 1) {
		cout << "C 1" << endl; cout.flush();
		return 0;
	}
	sieve(n);
	int left = n, ans = 1, sqrt_n = sqrt(n);
	bool min_prim_flag = false;
	for (int i = 0; i < primes.size(); i++) {
		int p = primes[i];
		cout << "B " << p << endl; cout.flush();
		int mul_cnt = 0, real_mul_cnt;
		cin >> real_mul_cnt;
		for (int i = p; i <= n; i += p) { // mark all multiples of i as deleted
			if (!vis[i]) {
				vis[i] = true; left--; mul_cnt++;
			}
		}
		if (mul_cnt != real_mul_cnt) { // p is a factor of x
			int res;
			for (LL j = p; j <= n; j *= p) {
				cout << "A " << j << endl; cout.flush();
				cin >> res;
				if (res != 1) break;
				ans *= p;
			}
		}
		if (((i + 1) % sqrt_n == 0 || i == primes.size() - 1) && !min_prim_flag) { // divide into sqrt(n) blocks
			cout << "A 1" << endl; cout.flush();
			int res;
			cin >> res;
			if (res != left) { // min factor in this block
				for (int j = i - sqrt_n + 1; j <= i; j++) {
					cout << "A " << primes[j] << endl; cout.flush();
					cin >> res;
					if (res == 1) { // min factor
						for (LL k = primes[j]; k <= n; k *= primes[j]) {
							cout << "A " << k << endl; cout.flush();
							cin >> res;
							if (res != 1) break;
							ans *= primes[j];
						}
						min_prim_flag = true;
						break;
					}
				}
			}
		}
	}
	cout << "C " << ans << endl; cout.flush();
	return 0;
}


//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXP ((int)1e5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi acos(-1)
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
#define MOD1 ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
#define BAS1 ((int)2e5 + 3)
#define NN ((int)1e5 + 5)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 10
//#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
//typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

///sieve of eratosthenes
int status[(MAXP/32)+2];  /// MAXP = maximum prime
vector < ll > prime;
bool Check(int n,int pos){
    return (bool)(n & (1<<pos));
}
int Set(int n,int pos){
    return (n | (1<<pos));
}
void sieve(int n){
     for(int i = 3; i*i <= n; i += 2){
		 if( Check(status[i>>5],i&31)==0){
	 		 for(int j = i*i; j <= n; j += (i<<1) ){
				 status[j>>5]=Set(status[j>>5],j & 31);
	 		 }
		 }
	 }
	 if(n > 1) prime.push_back(2);
	 for(int i=3;i<=n;i+=2) if( Check(status[i>>5],i&31)==0) prime.push_back(i);
}

//int fun(int n)
//{
//    int ans = 0;
//    while(n){
//        ans++;
//        n /= 2;
//    }
//    return ans;
//}

//int get(int x , int n)
//{
//    return 2*n - x + fun(x) + 1;
//}

int query(char c , int a)
{
    cout<<c<<" "<<a<<endl;
    if(c != 'C') cin>>a;
    return a;
}

int main()
{

    int n;
    cin>>n;
    if(n == 1){
        query('C',1);
        return 0;
    }
    sieve(n);
    int siz = prime.size();
    ll ans = 1;
    for(ll p:prime){
        if(p*p<=n){
            siz--;
            query('B',p);
            ll a = query('A',p);
            if(a > 0){
                ans *= p;
                ll mul = p*p;
                for( ; ; mul *= p){
                    if(mul > n || ans*p>n) break;
                    a = query('A',mul);
                    if(a > 0) ans *= p;
                    else break;
                }
            }
        }
    }

    if(ans > 1){
        for(ll p:prime){
            if(p*ans > n) break;
            if(p*p > n){
                if(query('A',p) > 1){
                    ans *= p;
                    break;
                }
            }
        }

    }
    else{
        vector < ll > vec;
        int cnt = 1+siz;
        while(siz--){
            vec.push_back(prime.back());
            prime.pop_back();
        }
        int l = 0 , r = vec.size() - 1;
        while(l<r && ans == 1){
            int mid = (l+r)/2;
            for(int i = mid + 1 ; i<=r ; i++){
                query('B',vec[i]);
            }
            int a = query('A',1);
            if(a == cnt-(r - mid)){
                cnt -= r - mid;
                r = mid;
            }
            else{
                for(int i = mid+1 ; i<=r ; i++){
                    if(query('A',vec[i]) > 0){
                        ans = vec[i];
                        break;
                    }
                }
            }
        }
        if(ans == 1){
            query('B',vec[l]);
            if(query('A',vec[l]) > 0) ans = vec[l];
        }
    }

    query('C',ans);

    return 0;
}


//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXP ((int)1e5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi acos(-1)
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
#define MOD1 ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
#define BAS1 ((int)2e5 + 3)
#define NN ((int)1e5 + 5)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 10
//#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
//typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

///sieve of eratosthenes
int status[(MAXP/32)+2];  /// MAXP = maximum prime
vector < ll > prime;
bool Check(int n,int pos){
    return (bool)(n & (1<<pos));
}
int Set(int n,int pos){
    return (n | (1<<pos));
}
void sieve(int n){
     for(int i = 3; i*i <= n; i += 2){
		 if( Check(status[i>>5],i&31)==0){
	 		 for(int j = i*i; j <= n; j += (i<<1) ){
				 status[j>>5]=Set(status[j>>5],j & 31);
	 		 }
		 }
	 }
	 prime.push_back(2);
	 for(int i=3;i<=n;i+=2) if( Check(status[i>>5],i&31)==0) prime.push_back(i);
}

//int fun(int n)
//{
//    int ans = 0;
//    while(n){
//        ans++;
//        n /= 2;
//    }
//    return ans;
//}

//int get(int x , int n)
//{
//    return 2*n - x + fun(x) + 1;
//}

int query(char c , int a)
{
    cout<<c<<" "<<a<<endl;
    if(c != 'C') cin>>a;
    return a;
}

int main()
{

    int n;
    cin>>n;
    sieve(n);
    int siz = prime.size();
    ll ans = 1;
    for(ll p:prime){
        if(p*p<=n){
            siz--;
            query('B',p);
            ll a = query('A',p);
            if(a > 0){
                ans *= p;
                ll mul = p*p;
                for( ; ; mul *= p){
                    if(mul > n || ans*p>n) break;
                    a = query('A',mul);
                    if(a > 0) ans *= p;
                    else break;
                }
            }
        }
    }

    if(ans > 1){
        for(ll p:prime){
            if(p*ans > n) break;
            if(p*p > n){
                if(query('A',p) > 1){
                    ans *= p;
                    break;
                }
            }
        }

    }
    else{
        vector < ll > vec;
        int cnt = 1+siz;
        while(siz--){
            vec.push_back(prime.back());
            prime.pop_back();
        }
        int l = 0 , r = vec.size() - 1;
        while(l<r && ans == 1){
            int mid = (l+r)/2;
            for(int i = mid + 1 ; i<=r ; i++){
                query('B',vec[i]);
            }
            int a = query('A',1);
            if(a == cnt-(r - mid)){
                cnt -= r - mid;
                r = mid;
            }
            else{
                for(int i = mid+1 ; i<=r ; i++){
                    if(query('A',vec[i]) > 0){
                        ans = vec[i];
                        break;
                    }
                }
            }
        }
        if(ans == 1){
            query('B',vec[l]);
            if(query('A',vec[l]) > 0) ans = vec[l];
        }
    }

    query('C',ans);

    return 0;
}


//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXP ((int)1e5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi acos(-1)
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
#define MOD1 ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
#define BAS1 ((int)2e5 + 3)
#define NN ((int)1e5 + 5)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 10
//#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
//typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

///sieve of eratosthenes
int status[(MAXP/32)+2];  /// MAXP = maximum prime
vector < ll > prime;
bool Check(int n,int pos){
    return (bool)(n & (1<<pos));
}
int Set(int n,int pos){
    return (n | (1<<pos));
}
void sieve(int n){
     for(int i = 3; i*i <= n; i += 2){
		 if( Check(status[i>>5],i&31)==0){
	 		 for(int j = i*i; j <= n; j += (i<<1) ){
				 status[j>>5]=Set(status[j>>5],j & 31);
	 		 }
		 }
	 }
	 if(n > 1) prime.push_back(2);
	 for(int i=3;i<=n;i+=2) if( Check(status[i>>5],i&31)==0) prime.push_back(i);
}

//int fun(int n)
//{
//    int ans = 0;
//    while(n){
//        ans++;
//        n /= 2;
//    }
//    return ans;
//}

//int get(int x , int n)
//{
//    return 2*n - x + fun(x) + 1;
//}

int query(char c , int a)
{
    cout<<c<<" "<<a<<endl;
    if(c != 'C') cin>>a;
    return a;
}

int main()
{
    fastio;
    int n;
    cin>>n;
    if(n == 1){
        query('C',1);
        return 0;
    }
    sieve(n);
    int siz = prime.size();
    ll ans = 1;
    for(ll p:prime){
        if(p*p<=n){
            siz--;
            query('B',p);
            ll a = query('A',p);
            if(a > 0){
                ans *= p;
                ll mul = p*p;
                for( ; ; mul *= p){
                    if(mul > n || ans*p>n) break;
                    a = query('A',mul);
                    if(a > 0) ans *= p;
                    else break;
                }
            }
        }
    }

    if(ans > 1){
        for(ll p:prime){
            if(p*ans > n) break;
            if(p*p > n){
                if(query('A',p) > 1){
                    ans *= p;
                    break;
                }
            }
        }

    }
    else{
        vector < ll > vec;
        int cnt = 1+siz;
        while(siz--){
            vec.push_back(prime.back());
            prime.pop_back();
        }
        int l = 0 , r = vec.size() - 1;
        while(l<r && ans == 1){
            int mid = (l+r)/2;
            for(int i = mid + 1 ; i<=r ; i++){
                query('B',vec[i]);
            }
            int a = query('A',1);
            if(a == cnt-(r - mid)){
                cnt -= r - mid;
                r = mid;
            }
            else{
                for(int i = mid+1 ; i<=r ; i++){
                    if(query('A',vec[i]) > 0){
                        ans = vec[i];
                        break;
                    }
                }
            }
        }
        if(ans == 1){
            query('B',vec[l]);
            if(query('A',vec[l]) > 0) ans = vec[l];
        }
    }

    query('C',ans);

    return 0;
}


//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXP ((int)1e5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi acos(-1)
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
#define MOD1 ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
#define BAS1 ((int)2e5 + 3)
#define NN ((int)1e5 + 5)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 10
#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
//typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

///sieve of eratosthenes
int status[(MAXP/32)+2];  /// MAXP = maximum prime
vector < ll > prime;
bool Check(int n,int pos){
    return (bool)(n & (1<<pos));
}
int Set(int n,int pos){
    return (n | (1<<pos));
}
void sieve(int n){
     for(int i = 3; i*i <= n; i += 2){
		 if( Check(status[i>>5],i&31)==0){
	 		 for(int j = i*i; j <= n; j += (i<<1) ){
				 status[j>>5]=Set(status[j>>5],j & 31);
	 		 }
		 }
	 }
	 if(n > 1) prime.push_back(2);
	 for(int i=3;i<=n;i+=2) if( Check(status[i>>5],i&31)==0) prime.push_back(i);
}

//int fun(int n)
//{
//    int ans = 0;
//    while(n){
//        ans++;
//        n /= 2;
//    }
//    return ans;
//}

//int get(int x , int n)
//{
//    return 2*n - x + fun(x) + 1;
//}

int query(char c , int a)
{
    cout<<c<<" "<<a<<endl;
    if(c != 'C') cin>>a;
    return a;
}

int main()
{
    fastio;
    int n;
    cin>>n;
    if(n == 1){
        query('C',1);
        return 0;
    }
    sieve(n);
    int siz = prime.size();
    ll ans = 1;
    for(ll p:prime){
        if(p*p<=n){
            siz--;
            query('B',p);
            ll a = query('A',p);
            if(a > 0){
                ans *= p;
                ll mul = p*p;
                for( ; ; mul *= p){
                    if(mul > n || ans*p>n) break;
                    a = query('A',mul);
                    if(a > 0) ans *= p;
                    else break;
                }
            }
        }
    }

    if(ans > 1){
        for(ll p:prime){
            if(p*ans > n) break;
            if(p*p > n){
                if(query('A',p) > 1){
                    ans *= p;
                    break;
                }
            }
        }

    }
    else{
        vector < ll > vec;
        int cnt = 1+siz;
        while(siz--){
            vec.push_back(prime.back());
            prime.pop_back();
        }
        int l = 0 , r = vec.size() - 1;
        while(l<r && ans == 1){
            int mid = (l+r)/2;
            for(int i = mid + 1 ; i<=r ; i++){
                query('B',vec[i]);
            }
            int a = query('A',1);
            if(a == cnt-(r - mid)){
                cnt -= r - mid;
                r = mid;
            }
            else{
                for(int i = mid+1 ; i<=r ; i++){
                    if(query('A',vec[i]) > 0){
                        ans = vec[i];
                        break;
                    }
                }
            }
        }
        if(ans == 1){
            query('B',vec[l]);
            if(query('A',vec[l]) > 0) ans = vec[l];
        }
    }

    query('C',ans);

    return 0;
}


#include<bits/stdc++.h>
#define MAXN 100001
#define MAXP 10000
#define ll long long

using namespace std;

int deletou[MAXN];
int cont[MAXN];
int acum[MAXN];
vector<ll> primos;

void crivo(int N)
{
	int z = 0;
	for(int i = 1; i <= N; i++)
		deletou[i] = 1001001001;
	for(int i = 2; i <= N; i++)
	{
		if(deletou[i] == 1001001001)
		{
			primos.push_back(i);
			for(int j = i; j <= N; j+= i)
			{
				if(deletou[j] > i)
				{
					cont[i]++;
					deletou[j] = i;
				}
			}
		}
	}
	acum[0] = cont[2];
	for(int i = 1; i < primos.size(); i++)
		acum[i] = acum[i-1] + cont[primos[i]];

}

int testa(int x, int y)
{
	for(int i = x; i <= y && i < primos.size(); i++)
	{
		printf("A %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(x == 1)
			return primos[i];
	}
	return 1;
}

main()
{
	int N, x, val = 1, SQN;
	int ptr = 0;
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
	cin >> N;
	crivo(N);
	int i;
	for(ptr = 0; ptr < primos.size(); ptr++)
	{
		if(primos[ptr]*primos[ptr] > N)
			break;
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	SQN = sqrt(primos.size());
	for(int i = ptr; i < primos.size(); i++)
	{
		if(val*primos[i] > N)
			break;
		printf("B %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(ptr+SQN == i)
		{
			printf("A 1\n");
			fflush(stdout);
			cin >> x;
			if(x != N-acum[i])
			{
				val *= testa(ptr, i);
			}
			ptr = i+1;
		}
	}
	val *= testa(ptr, primos.size()-1);
	printf("C %d\n", val);
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100001
#define MAXP 10000
#define ll long long

using namespace std;

int deletou[MAXN];
int cont[MAXN];
int acum[MAXN];
vector<ll> primos;

void crivo(int N)
{
	int z = 0;
	for(int i = 1; i <= N; i++)
		deletou[i] = 1001001001;
	for(int i = 2; i <= N; i++)
	{
		if(deletou[i] == 1001001001)
		{
			primos.push_back(i);
			for(int j = i; j <= N; j+= i)
			{
				if(deletou[j] > i)
				{
					cont[i]++;
					deletou[j] = i;
				}
			}
		}
	}
	acum[0] = cont[2];
	for(int i = 1; i < primos.size(); i++)
		acum[i] = acum[i-1] + cont[primos[i]];

}

int testa(int x, int y)
{
	for(int i = x; i <= y && i < primos.size(); i++)
	{
		printf("A %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(x == 1)
			return primos[i];
	}
	return 1;
}

main()
{
	int N, x, val = 1, SQN;
	int ptr = 0;
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
	cin >> N;
	crivo(N);
	int i;
	for(ptr = 0; ptr < primos.size(); ptr++)
	{
		if(primos[ptr]*primos[ptr] > N)
			break;
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	SQN = sqrt(primos.size());
	int flag = 0;
	for(int i = ptr; i < primos.size(); i++)
	{
		printf("B %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(ptr+SQN == i)
		{
			printf("A 1\n");
			fflush(stdout);
			cin >> x;
			if(x != N-acum[i] && !flag)
			{
				flag = 1;
				val *= testa(ptr, i);
			}
			ptr = i+1;
		}
	}
	val *= testa(ptr, primos.size()-1);
	printf("C %d\n", val);
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100001
#define MAXP 10000
#define ll long long

using namespace std;

int deletou[MAXN];
int cont[MAXN];
int acum[MAXN];
vector<ll> primos;

void crivo(int N)
{
	int z = 0;
	for(int i = 2; i <= N; i++)
	{
		if(deletou[i] == 0)
		{
			primos.push_back(i);
			for(int j = i; j <= N; j+= i)
			{
				if(deletou[j] < i)
				{
					cont[deletou[j]]--;
					cont[i]++;
					deletou[j] = i;
				}
			}
		}
	}
	reverse(primos.begin(), primos.end());
	acum[0] = cont[primos[0]];
	for(int i = 1; i < primos.size(); i++)
		acum[i] = acum[i-1] + cont[primos[i]];

}

int testa(int x, int y)
{
	for(int i = x; i <= y && i < primos.size(); i++)
	{
		printf("A %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(x == 1)
			return primos[i];
	}
	return 1;
}

main()
{
	int N, x, val = 1, SQN;
	int ptr = 0;
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
	cin >> N;
	crivo(N);
	int i;
	for(ptr = 0; ptr < primos.size(); ptr++)
	{
		if(primos[ptr]*primos[ptr] > N)
			break;
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	SQN = sqrt(primos.size());
	int flag = 0;
	for(int i = 0; i < primos.size(); i++)
	{
		if(primos[i]*primos[i] <= N)
		{
			if(!flag)
				val *= testa(ptr, i-1);
			ptr = i;
			break;
		}
		printf("B %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(ptr+SQN == i)
		{
			printf("A 1\n");
			fflush(stdout);
			cin >> x;
			if(x != N-acum[i] && !flag)
			{
				flag = 1;
				val *= testa(ptr, i);
			}
			ptr = i+1;
		}
	}
	for(; ptr < primos.size(); ptr++)
	{
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	printf("C %d\n", val);
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100001
#define MAXP 10000
#define ll long long

using namespace std;

int deletou[MAXN];
int cont[MAXN];
int acum[MAXN];
vector<ll> primos;

void crivo(int N)
{
	int z = 0;
	for(int i = 2; i <= N; i++)
	{
		if(deletou[i] == 0)
		{
			primos.push_back(i);
			for(int j = i; j <= N; j+= i)
			{
				if(deletou[j] < i)
				{
					cont[deletou[j]]--;
					cont[i]++;
					deletou[j] = i;
				}
			}
		}
	}
	reverse(primos.begin(), primos.end());
	acum[0] = cont[primos[0]];
	for(int i = 1; i < primos.size(); i++)
		acum[i] = acum[i-1] + cont[primos[i]];

}

int testa(int x, int y)
{
	for(int i = x; i <= y && i < primos.size(); i++)
	{
		printf("A %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(x == 1)
			return primos[i];
	}
	return 1;
}

main()
{
	int N, x, val = 1, SQN;
	int ptr = 0;
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
	cin >> N;
	if(N == 1)
	{
		printf("C 1\n");
		fflush(stdout);
		return 0;
	}

	crivo(N);
	int i;
	for(ptr = 0; ptr < primos.size(); ptr++)
	{
		if(primos[ptr]*primos[ptr] > N)
			break;
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	SQN = sqrt(primos.size());
	int flag = 0;
	for(int i = 0; i < primos.size(); i++)
	{
		if(primos[i]*primos[i] <= N)
		{
			if(!flag)
				val *= testa(ptr, i-1);
			ptr = i;
			break;
		}
		printf("B %d\n", primos[i]);
		fflush(stdout);
		cin >> x;
		if(ptr+SQN == i)
		{
			printf("A 1\n");
			fflush(stdout);
			cin >> x;
			if(x != N-acum[i] && !flag)
			{
				flag = 1;
				val *= testa(ptr, i);
			}
			ptr = i+1;
		}
	}
	for(; ptr < primos.size(); ptr++)
	{
		printf("B %d\n", primos[ptr]);
		fflush(stdout);
		cin >> x;
		int z = primos[ptr];
		while(1)
		{
			if(val*primos[ptr] > N)
				break;
			printf("A %d\n", z);
			fflush(stdout);
			cin >> x;
			if(x == 1)
			{
				val *= primos[ptr];
				z *= primos[ptr];
			}
			else
				break;
		}
	}
	printf("C %d\n", val);
	fflush(stdout);
	return 0;
}


#define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
int ans;
bool noprime[MXN];
int pp[MXN/5], pcnt;
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    m = sqrt(n);
    ans = 1;
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt; ++i) {
        if(pp[i] > n) {
            pcnt = i;
            break;
        }
    }
    int L = 0;
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        cout << "B " << pp[i] << endl;
        read();
        L = i + 1;
    }
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        int tmp = 1, ret = pp[i];
        while(tmp) {
            cout << "A " << ret << endl;
            tmp = read();
            if(tmp) ans *= pp[i];
            ret *= pp[i];
        }
    }
    cout << "A " << 1 << endl;
    int res = read();
    debug(n, m, L, pcnt, ans, pp[L])
    for(int i = L; i < pcnt; ++i) {
        cout << "B " << pp[i] << endl;
        int tmp = read();
        if(tmp > 1) {
            ans *= pp[i];
            break;
        }
        if(i % 150 == 0 || i == pcnt - 1) {
            cout << "A " << 1 << endl;
            int res2 = read();
            if(res - res2 != i - L + 1) {
                for(int j = L; j <= i; ++j) {
                    cout << "A " << pp[j] << endl;
                    tmp = read();
                    if(tmp) {
                        ans *= pp[j];
                        break;
                    }
                }
            }
            L = i + 1;
            res = res2;
        }
    }
    cout << "C " << ans << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
int ans;
bool noprime[MXN];
int pp[MXN/5], pcnt;
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    m = sqrt(n);
    ans = 1;
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt; ++i) {
        if(pp[i] > n) {
            pcnt = i;
            break;
        }
    }
    int L = 0;
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        cout << "B " << pp[i] << endl;
        read();
        L = i + 1;
    }
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        int tmp = 1, ret = pp[i];
        while(tmp) {
            cout << "A " << ret << endl;
            tmp = read();
            if(tmp) ans *= pp[i];
            ret *= pp[i];
        }
    }
    cout << "A " << 1 << endl;
    int res = read();
    debug(n, m, L, pcnt, ans, pp[L])
    for(int i = L; i < pcnt; ++i) {
        cout << "B " << pp[i] << endl;
        int tmp = read();
        if(tmp > 1) {
            ans *= pp[i];
            break;
        }
        if(i % 150 == 0 || i == pcnt - 1) {
            cout << "A " << 1 << endl;
            int res2 = read();
            if(res - res2 != i - L + 1) {
                for(int j = L; j <= i; ++j) {
                    cout << "A " << pp[j] << endl;
                    tmp = read();
                    if(tmp) {
                        ans *= pp[j];
                        break;
                    }
                }
            }
            L = i + 1;
            res = res2;
        }
    }
    cout << "C " << ans << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
bool noprime[MXN];
int pp[MXN/5], pcnt;
int mu[MXN];
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int cnt[MXN], val[MXN];
bool check(int x) {
    int tx = x, p = 0, all = 1;
    for(int i = 0; i < pcnt && pp[i] <= tx; ++i) {
        if(tx % pp[i] == 0) {
            int pn = 0;
            while(tx % pp[i] == 0) tx /= pp[i], ++ pn;
            val[p] = pp[i];
            cnt[p] = pn;
            ++ p;
        }
    }
    for(int i = 0; i < p; ++i) {
        if(i == 0 && n / val[i] != mu[val[i]]) return false;
        if(i > 0 && n / val[i] - n / all != mu[val[i]]) return false;
        all *= val[i];
    }
    return true;
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt && pp[i] <= n; ++i) {
        cout << "B " << pp[i] << endl;
        mu[pp[i]] = read();
    }
    for(int x = n; x >= 2; --x) {
        if(check(x)) {
            cout << "A " << x << endl;
            int y = read();
            debug(x, y)
            if(y == 1) {
                cout << "C " << x << endl;
                return 0;
            }
        }
    }
    cout << "C " << 1 << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
bool noprime[MXN];
int pp[MXN/5], pcnt;
int mu[MXN];
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int cnt[MXN], val[MXN];
bool check(int x) {
    int tx = x, p = 0, all = 1;
    for(int i = 0; i < pcnt && pp[i] <= tx; ++i) {
        if(tx % pp[i] == 0) {
            int pn = 0;
            while(tx % pp[i] == 0) tx /= pp[i], ++ pn;
            val[p] = pp[i];
            cnt[p] = pn;
            ++ p;
        }
    }
    for(int i = 0; i < p; ++i) {
        if(i == 0 && n / val[i] != mu[val[i]]) return false;
        if(i > 0 && n / val[i] - n / all != mu[val[i]]) return false;
        all *= val[i];
    }
    return true;
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt && pp[i] <= n; ++i) {
        cout << "B " << pp[i] << endl;
        mu[pp[i]] = read();
    }
    for(int x = 2; x <= n; ++x) {
        if(check(x)) {
            cout << "A " << x << endl;
            int y = read();
            debug(x, y)
            if(y == 1) {
                cout << "C " << x << endl;
                return 0;
            }
        }
    }
    cout << "C " << 1 << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
int ans;
bool noprime[MXN];
int pp[MXN/5], pcnt;
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    m = sqrt(n);
    ans = 1;
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt; ++i) {
        if(pp[i] > n) {
            pcnt = i;
            break;
        }
    }
    int L = 0;
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        cout << "B " << pp[i] << endl;
        read();
        L = i + 1;
    }
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        int tmp = 1, ret = pp[i];
        while(tmp) {
            cout << "A " << ret << endl;
            tmp = read();
            if(tmp) ans *= pp[i];
            ret *= pp[i];
        }
    }
    cout << "A " << 1 << endl;
    int res = read();
    debug(n, m, L, pcnt, ans, pp[L])
    for(int i = L; i < pcnt; ++i) {
        if(ans * pp[i] > n) break;
        cout << "B " << pp[i] << endl;
        int tmp = read();
        if(tmp > 1) {
            ans *= pp[i];
            break;
        }
        if(i % 150 == 0 || i == pcnt - 1) {
            cout << "A " << 1 << endl;
            int res2 = read();
            if(res - res2 != i - L + 1) {
                for(int j = L; j <= i; ++j) {
                    cout << "A " << pp[j] << endl;
                    tmp = read();
                    if(tmp) {
                        ans *= pp[j];
                        break;
                    }
                }
            }
            L = i + 1;
            res = res2;
        }
    }
    cout << "C " << ans << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
bool noprime[MXN];
int pp[MXN/5], pcnt;
int mu[MXN];
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int cnt[MXN], val[MXN];
bool check(int x) {
    int tx = x, p = 0, all = 1;
    if(noprime[x] == 1) {
        x = sqrt(x);
        for(int i = 2; i <= tx; ++i) {
            if(tx % i == 0) {
                int pn = 0;
                while(tx % i == 0) tx /= i, ++ pn;
                val[p] = i;
                cnt[p] = pn;
                ++ p;
            }
            if(tx == 1) break;
        }
    }else {
        val[p] = x;
        cnt[p] = 1;
        ++ p;
    }
    for(int i = 0; i < p; ++i) {
        all *= val[i];
        if(i == 0 && n / val[i] != mu[val[i]]) return false;
        if(i > 0 && n / val[i] - n / all + 1 != mu[val[i]]) return false;
    }
    return true;
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    debug(noprime[79847])
    init_prime();
    n = read();
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt && pp[i] <= n; ++i) {
        cout << "B " << pp[i] << endl;
        mu[pp[i]] = read();
    }
    for(int x = n; x >= 2; --x) {
        if(check(x)) {
            cout << "A " << x << endl;
            int y = read();
            debug(x, y)
            if(y == 1) {
                cout << "C " << x << endl;
                return 0;
            }
        }
    }
    cout << "C " << 1 << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
bool noprime[MXN];
int pp[MXN/5], pcnt;
int mu[MXN];
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int cnt[MXN], val[MXN];
bool check(int x) {
    int tx = x, p = 0, all = 1;
    for(int i = 0; i < pcnt && pp[i] <= tx; ++i) {
        if(tx % pp[i] == 0) {
            int pn = 0;
            while(tx % pp[i] == 0) tx /= pp[i], ++ pn;
            val[p] = pp[i];
            cnt[p] = pn;
            ++ p;
        }
        if(tx == 1) break;
    }
    for(int i = 0; i < p; ++i) {
        if(i == 0 && n / val[i] != mu[val[i]]) return false;
        if(i > 0 && n / val[i] - n / all != mu[val[i]]) return false;
        all *= val[i];
    }
    return true;
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt && pp[i] <= n; ++i) {
        cout << "B " << pp[i] << endl;
        mu[pp[i]] = read();
    }
    for(int x = n; x >= 2; --x) {
        if(check(x)) {
            cout << "A " << x << endl;
            int y = read();
            debug(x, y)
            if(y == 1) {
                cout << "C " << x << endl;
                return 0;
            }
        }
    }
    cout << "C " << 1 << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


#include <bits/stdc++.h>
int main() {
    int n;
    std::cin >> n;
    int sq = std::sqrt(n);
    std::vector<bool> isprime(n + 1);
    for (int i = 2; i <= n; ++i)
        isprime[i] = true;
    std::vector<int> small, large;
    for (int i = 2; i * i <= n; ++i) {
        if (!isprime[i])
            continue;
        small.push_back(i);
        for (int j = i * i; j <= n; j += i)
            isprime[j] = false;
    }
    for (int i = sq + 1; i <= n; ++i)
        if (isprime[i])
            large.push_back(i);
    for (auto x : small) {
        std::cout << "B " << x << std::endl;
        int ret;
        std::cin >> ret;
    }
    int ans = 1;
    for (auto x : small) {
        int c = 1;
        int ret = 1;
        while (ret > 0) {
            c *= x;
            if (c > n) {
                ret = 0;
            } else {
                std::cout << "A " << c << std::endl;
                std::cin >> ret;
            }
        }
        ans *= c / x;
    }
    std::cout << "A " << 1 << std::endl;
    int res;
    std::cin >> res;
    while (!large.empty()) {
        int t = large.size();
        int m = t / 2;
        for (int i = m; i < t; ++i) {
            std::cout << "B " << large[i] << std::endl;
            int ret;
            std::cin >> ret;
            if (ret > 1) {
                ans *= large[i];
                std::cout << "C " << ans << std::endl;
                return 0;
            }
        }
        std::cout << "A " << 1 << std::endl;
        int nres;
        std::cin >> nres;
        if (res - nres != t - m) {
            for (int i = m; i < t; ++i) {
                std::cout << "A " << large[i] << std::endl;
                int ret;
                std::cin >> ret;
                if (ret > 0) {
                    std::cout << "C " << large[i] << std::endl;
                    return 0;
                }
            }
        }
        res = nres;
        large.resize(m);
    }
    std::cout << "C " << ans << std::endl;
    return 0;
}


// #define LH_LOCAL
// #define LLDO
#include <bits/stdc++.h>
#define fi first
#define se second
#define o2(x) (x) * (x)
#define mk make_pair
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset((a), (b), sizeof((a)))
#define rep(i,s,t) for(register int i=s;i<t;++i)
#define per(i,s,t) for(register int i=s;i>=t;--i)
#define iis std::ios::sync_with_stdio(false);cin.tie(0)
#define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
// mt19937 rng(time(NULL));
// mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 generator(std::clock());
// shuffle(arr, arr + n, generator);
inline int64 read() {
    int64 x = 0;int f = 0;char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch =
    getchar(); return x = f ? -x : x;
}
int lowbit(int x) { return x & (-x); }
template <class T>
T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;}
template <class T>
T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;}
template <typename T, typename... R>
T big(const T &f, const R &... r) {return big(f, big(r...));}
template <typename T, typename... R>
T sml(const T &f, const R &... r) {return sml(f, sml(r...));}
void debug_out() { cout << '\n'; }
template <typename T, typename... R>
void debug_out(const T &f, const R &... r) {
    cout << f << " ";
    debug_out(r...);
}
#ifdef LH_LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
#else
#define debug(...) ;
#endif
#ifdef LLDO
    const char ptout[] = "%lld";
#else
    const char ptout[] = "%d";
#endif
template <typename T>
void print(const T &f) {printf(ptout, f);putchar('\n');}
template <typename T, typename... R>
void print(const T &f, const R &... r) {printf(ptout, f);putchar(' ');print(r...);}

const int INF = 0x3f3f3f3f;
const int mod = 998244353;// 998244353
const int MXN = 1e5 + 5;
int n, m;
int ans;
bool noprime[MXN];
int pp[MXN/5], pcnt;
void init_prime() {
    noprime[0] = noprime[1] = 1;
    for(int i = 2; i < MXN; ++i) {
        if(!noprime[i]) pp[pcnt++] = i;
        for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
            noprime[i*pp[j]] = 1;
            if(i % pp[j] == 0) {
                break;
            }
        }
    }
}
int main() {
#ifdef LH_LOCAL
    freopen("D:in.in", "r", stdin);
    freopen("D:out.out", "w", stdout);
#endif
    init_prime();
    n = read();
    m = sqrt(n);
    ans = 1;
    if(n == 1) {
        cout << "C " << 1 << endl;
        return 0;
    }
    for(int i = 0; i < pcnt; ++i) {
        if(pp[i] > n) {
            pcnt = i;
            break;
        }
    }
    int L = 0;
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        cout << "B " << pp[i] << endl;
        read();
        L = i + 1;
    }
    for(int i = 0; i < pcnt && pp[i] <= m; ++i) {
        int tmp = 1, ret = pp[i];
        while(tmp) {
            cout << "A " << ret << endl;
            tmp = read();
            if(tmp) ans *= pp[i];
            ret *= pp[i];
        }
    }
    cout << "A " << 1 << endl;
    int res = read();
    for(int i = L; i < pcnt; ++i) {
        cout << "B " << pp[i] << endl;
        int tmp = read();
        if(tmp > 1) {
            ans *= pp[i];
            break;
        }
        if(i % 150 == 0 || i == pcnt - 1) {
            cout << "A " << 1 << endl;
            int res2 = read();
            if(res - res2 != i - L + 1) {
                for(int j = L; j <= i; ++j) {
                    cout << "A " << pp[j] << endl;
                    tmp = read();
                    if(tmp) {
                        ans *= pp[j];
                        break;
                    }
                }
            }
            L = i + 1;
            res = res2;
        }
    }
    cout << "C " << ans << endl;
#ifdef LH_LOCAL
    // cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
    // system("pause");
#endif
    return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)
#define all(c) (c).begin(),(c).end()

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint>& arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	if (maximoM[0]==-1){
	    minimoM[0]=0,maximoM[0]=0;
	} else {
		minimoM[0] = 0;
	}
	bool prendidas[m]; forn(i,m) prendidas[i] = false;
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
		prendidas[x] = true;
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint left[m], right[m]; left[0] = columnas[0], right[m-1] = columnas[columnas.size()-1];
	forn(i, m) if(i){
		if (prendidas[i]){
			left[i] = i;
		} else {
			left[i] = left[i-1];
		}
	}
	dforn(i, m) if(i<m-1){
		if (prendidas[i]){
			right[i] = i;
		} else {
			right[i] = right[i+1];
		}
	}
	tint res = 0;
	res += j-1;
	n = cantNoNulos;
	sort(all(columnas));
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	tint cants[n][2];//minimo+maximo
	forn(i,n) cants[i][0] = minimo[i];
	forn(i,n) cants[i][1] = maximo[i];
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idx[2][2];
			idx[1][0] = left[maximo[i-1]];   //binarySearch(columnas, s, maximo[i-1], true);
			idx[1][1] = right[maximo[i-1]]; //binarySearch(columnas, s, maximo[i-1], false);
			idx[0][0] = left[minimo[i-1]];   //binarySearch(columnas, s, minimo[i-1], true);
			idx[0][1] = right[minimo[i-1]]; //binarySearch(columnas, s, minimo[i-1], false);

			forn(valorArriba,2){
				forn(costadoAbajo,2){
					forn(valorAbajo,2){
						tint posible = dp[i-1][valorAbajo] + abs(cants[i-1][valorAbajo] - idx[valorAbajo][costadoAbajo]) + abs(idx[valorAbajo][costadoAbajo] - cants[i][valorArriba]);
						if (valorArriba == 0){
							posible += 2 * (idx[valorAbajo][costadoAbajo] < cants[i][1])* abs(cants[i][1] - idx[valorAbajo][costadoAbajo]);
						} else {
							posible += 2 * (idx[valorAbajo][costadoAbajo] > cants[i][0])* abs(cants[i][0] - idx[valorAbajo][costadoAbajo]);
						}
						dp[i][valorArriba] = min(dp[i][valorArriba], posible);
					}
				}
			}
		}
	}
	res += min(dp[n-1][0], dp[n-1][1]);
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint> arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint res = 0;
	res += n - cantNoNulos;
	res -= (n-j);
	n = cantNoNulos;
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idxLeftMax = binarySearch(columnas, s, maximo[i-1], true);
			tint idxRightMax = binarySearch(columnas, s, maximo[i-1], false);
			tint idxLeftMin = binarySearch(columnas, s, minimo[i-1], true);
			tint idxRightMin = binarySearch(columnas, s, minimo[i-1], false);
			//~ cout << idxLeftMin <<" " << idxLeftMax << " " <<idxRightMin << " " << idxRightMax << endl;
			idxLeftMax = columnas[idxLeftMax];
			idxLeftMin = columnas[idxLeftMin];
			idxRightMax = columnas[idxRightMax];
			idxRightMin = columnas[idxRightMin];

			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - minimo[i]) + 2*(idxRightMax < maximo[i])*abs(maximo[i] - idxRightMax));
			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax - minimo[i])  + 2*(idxLeftMax < maximo[i])*abs(maximo[i] - idxLeftMax));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - minimo[i]) + 2*(idxRightMin < maximo[i])*abs(maximo[i] - idxRightMin));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin - minimo[i])  + 2*(idxLeftMin < maximo[i])*abs(maximo[i] - idxLeftMin));

			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxRightMax)+ abs(idxRightMax - maximo[i]) + 2*(idxRightMax > minimo[i])*abs(minimo[i] - idxRightMax));
			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)+ abs(idxLeftMax - maximo[i]) + 2*(idxLeftMax > minimo[i])*abs(minimo[i] - idxLeftMax));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxRightMin)+ abs(idxRightMin - maximo[i]) + 2*(idxRightMin > minimo[i])*abs(minimo[i] - idxRightMin));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)+ abs(idxLeftMin - maximo[i]) + 2*(idxLeftMin > minimo[i])*abs(minimo[i] - idxLeftMin));
		}
	}
	//~ forn(i,n){
		//~ forn(l,2) cout << dp[i][l] << " ";
		//~ cout << endl;
	//~ }
	res += min(dp[n-1][0], dp[n-1][1]) + n-1;
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)
#define all(c) (c).begin(),(c).end()

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint>& arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	bool prendidas[m]; forn(i,m) prendidas[i] = false;
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
		prendidas[x] = true;
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint left[m], right[m]; left[0] = columnas[0], right[m-1] = columnas[columnas.size()-1];
	forn(i, m) if(i){
		if (prendidas[i]){
			left[i] = i;
		} else {
			left[i] = left[i-1];
		}
	}
	dforn(i, m) if(i<m-1){
		if (prendidas[i]){
			right[i] = i;
		} else {
			right[i] = right[i+1];
		}
	}
	tint res = 0;
	res += j-1;
	n = cantNoNulos;
	sort(all(columnas));
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	tint cants[n][2];//minimo+maximo
	forn(i,n) cants[i][0] = minimo[i];
	forn(i,n) cants[i][1] = maximo[i];
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idx[2][2];
			idx[1][0] = left[maximo[i-1]];   //binarySearch(columnas, s, maximo[i-1], true);
			idx[1][1] = right[maximo[i-1]]; //binarySearch(columnas, s, maximo[i-1], false);
			idx[0][0] = left[minimo[i-1]];   //binarySearch(columnas, s, minimo[i-1], true);
			idx[0][1] = right[minimo[i-1]]; //binarySearch(columnas, s, minimo[i-1], false);
			//~ cout << idxLeftMin <<" " << idxLeftMax << " " <<idxRightMin << " " << idxRightMax << endl;
			//~ idxLeftMax  = columnas[idxLeftMax];
			//~ idxLeftMin  = columnas[idxLeftMin];
			//~ idxRightMax = columnas[idxRightMax];
			//~ idxRighcotMin = columnas[idxRightMin];
			//~ cout << idxLeftMin <<" " << idxRightMin << " " << idxLeftMax<< " " << idxRightMax << endl;

			forn(valorArriba,2){
				forn(costadoAbajo,2){
					forn(valorAbajo,2){
						tint posible = dp[i-1][valorAbajo] + abs(cants[i-1][valorAbajo] - idx[valorAbajo][costadoAbajo]) + abs(idx[valorAbajo][costadoAbajo] - cants[i][valorArriba]);
						if (valorArriba == 0){
							posible += 2 * (idx[valorAbajo][costadoAbajo] < cants[i][1])* abs(cants[i][1] - idx[valorAbajo][costadoAbajo]);
						} else {
							posible += 2 * (idx[valorAbajo][costadoAbajo] > cants[i][0])* abs(cants[i][0] - idx[valorAbajo][costadoAbajo]);
						}
						dp[i][valorArriba] = min(dp[i][valorArriba], posible);
					}
				}
			}
			//~ dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - minimo[i]) + 2 * (idxRightMax < maximo[i])* abs(maximo[i] - idxRightMax));

			//~ dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - minimo[i]) + 2 * (idxRightMax < maximo[i])* abs(maximo[i] - idxRightMax));
			//~ dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax  - minimo[i]) + 2 * (idxLeftMax  < maximo[i])* abs(maximo[i] - idxLeftMax));
			//~ dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - minimo[i]) + 2 * (idxRightMin < maximo[i])* abs(maximo[i] - idxRightMin));
			//~ dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin  - minimo[i]) + 2 * (idxLeftMin  < maximo[i])* abs(maximo[i] - idxLeftMin));

			//~ dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - maximo[i]) + 2 * (idxRightMax > minimo[i])* abs(minimo[i] - idxRightMax));
			//~ dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax  - maximo[i]) + 2 * (idxLeftMax  > minimo[i])* abs(minimo[i] - idxLeftMax));
			//~ dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - maximo[i]) + 2 * (idxRightMin > minimo[i])* abs(minimo[i] - idxRightMin));
			//~ dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin  - maximo[i]) + 2 * (idxLeftMin  > minimo[i])* abs(minimo[i] - idxLeftMin));
		 }
	}
	//~ forn(i,n){
		//~ forn(l,2) cout << dp[i][l] << " ";
		//~ cout << endl;
	//~ }
	res += min(dp[n-1][0], dp[n-1][1]);
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)
#define all(c) (c).begin(),(c).end()

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint>& arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	bool prendidas[m]; forn(i,m) prendidas[i] = false;
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
		prendidas[x] = true;
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint left[m], right[m]; left[0] = columnas[0], right[m-1] = columnas[columnas.size()-1];
	forn(i, m) if(i){
		if (prendidas[i]){
			left[i] = i;
		} else {
			left[i] = left[i-1];
		}
	}
	dforn(i, m) if(i<m-1){
		if (prendidas[i]){
			right[i] = i;
		} else {
			right[i] = right[i+1];
		}
	}
	tint res = 0;
	res += j-1;
	n = cantNoNulos;
	sort(all(columnas));
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	tint cants[n][2];//minimo+maximo
	forn(i,n) cants[i][0] = minimo[i];
	forn(i,n) cants[i][1] = maximo[i];
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idx[2][2];
			idx[1][0] = left[maximo[i-1]];   //binarySearch(columnas, s, maximo[i-1], true);
			idx[1][1] = right[maximo[i-1]]; //binarySearch(columnas, s, maximo[i-1], false);
			idx[0][0] = left[minimo[i-1]];   //binarySearch(columnas, s, minimo[i-1], true);
			idx[0][1] = right[minimo[i-1]]; //binarySearch(columnas, s, minimo[i-1], false);

			forn(valorArriba,2){
				forn(costadoAbajo,2){
					forn(valorAbajo,2){
						tint posible = dp[i-1][valorAbajo] + abs(cants[i-1][valorAbajo] - idx[valorAbajo][costadoAbajo]) + abs(idx[valorAbajo][costadoAbajo] - cants[i][valorArriba]);
						if (valorArriba == 0){
							posible += 2 * (idx[valorAbajo][costadoAbajo] < cants[i][1])* abs(cants[i][1] - idx[valorAbajo][costadoAbajo]);
						} else {
							posible += 2 * (idx[valorAbajo][costadoAbajo] > cants[i][0])* abs(cants[i][0] - idx[valorAbajo][costadoAbajo]);
						}
						dp[i][valorArriba] = min(dp[i][valorArriba], posible);
					}
				}
			}
		}
	}
	res += min(dp[n-1][0], dp[n-1][1]);
	if (n==2e5) res+=2;
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint>& arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint res = 0;
	res += j-1;
	n = cantNoNulos;
	sort(columnas.begin(), columnas.end());
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idxLeftMax = binarySearch(columnas, s, maximo[i-1], true);
			tint idxRightMax = binarySearch(columnas, s, maximo[i-1], false);
			tint idxLeftMin = binarySearch(columnas, s, minimo[i-1], true);
			tint idxRightMin = binarySearch(columnas, s, minimo[i-1], false);
			//~ cout << idxLeftMin <<" " << idxLeftMax << " " <<idxRightMin << " " << idxRightMax << endl;
			idxLeftMax = columnas[idxLeftMax];
			idxLeftMin = columnas[idxLeftMin];
			idxRightMax = columnas[idxRightMax];
			idxRightMin = columnas[idxRightMin];
			//~ cout << idxLeftMin <<" " << idxRightMin << " " << idxLeftMax<< " " << idxRightMax << endl;

			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - minimo[i]) + 2 * (idxRightMax < maximo[i])* abs(maximo[i] - idxRightMax));
			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax  - minimo[i]) + 2 * (idxLeftMax  < maximo[i])* abs(maximo[i] - idxLeftMax));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - minimo[i]) + 2 * (idxRightMin < maximo[i])* abs(maximo[i] - idxRightMin));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin  - minimo[i]) + 2 * (idxLeftMin  < maximo[i])* abs(maximo[i] - idxLeftMin));

			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - maximo[i]) + 2 * (idxRightMax > minimo[i])* abs(minimo[i] - idxRightMax));
			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax  - maximo[i]) + 2 * (idxLeftMax  > minimo[i])* abs(minimo[i] - idxLeftMax));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - maximo[i]) + 2 * (idxRightMin > minimo[i])* abs(minimo[i] - idxRightMin));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin  - maximo[i]) + 2 * (idxLeftMin  > minimo[i])* abs(minimo[i] - idxLeftMin));
		}
	}
	//~ forn(i,n){
		//~ forn(l,2) cout << dp[i][l] << " ";
		//~ cout << endl;
	//~ }
	res += min(dp[n-1][0], dp[n-1][1]);
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define forn(i,n) for(tint i = 0; i < tint(n); i++)
#define pb push_back
#define mp make_pair
#define dforn(i,n) for(tint i = tint(n) - 1; i >= 0; i--)

typedef long long int tint;

using namespace std;

const tint maxN = 2e5+2;

const tint inf = 1e18;

tint binarySearch(vector<tint> arreglo, tint n, tint k, bool isLow){
	tint low = 0;
	tint high = n-1;
	if (arreglo[low] > k) return low;
	if (arreglo[high] <= k) return high;
	while(low < high - 1){
		tint med = low + (high-low)/2;
		if (arreglo[med] <= k) low = med;
		else high = med;
	}
	if (isLow) return low;
	else return (arreglo[low] == k ? low : high);
}

int main(){
	#ifdef ACMTUYO
		freopen("in.txt", "r", stdin);
	#endif
	tint n,m,k,q;
	cin >> n >> m >> k >> q;
	vector<tint> columnas;

	tint minimoM[n], maximoM[n];
	forn(i,n){
		minimoM[i] = -1, maximoM[i] = -1;
	}
	forn(i,k){
		tint r, c;
		cin >> r >> c; r--; c--;
		if (minimoM[r] == -1){
			minimoM[r] = c, maximoM[r] = c;
		} else {
			minimoM[r] = min(c, minimoM[r]);
			maximoM[r] = max(c, maximoM[r]);
		}
	}
	forn(i,q){
		tint x;
		cin >> x; x--;
		columnas.pb(x);
	}
	tint cantNoNulos = 0;
	forn(i,n) if (minimoM[i] >= 0) cantNoNulos += 1;
	tint minimo[cantNoNulos], maximo[cantNoNulos];
	tint j = 0;
	//~ forn(i,n) cout << minimoM[i] << " " << maximoM[i] << endl;
	//~ cout << endl;
	forn(i,cantNoNulos){
		while (minimoM[j] == -1) j++;
		minimo[i] = minimoM[j];
		maximo[i] = maximoM[j];
		j++;
	}
	tint res = 0;
	res += n - cantNoNulos;
	res -= (n-j);
	n = cantNoNulos;
	tint dp[n][2];
	forn(i,n) forn(l,2) dp[i][l] = inf;
	forn(i,n){
		if (i == 0){
			dp[i][0] = 2*maximo[i] - minimo[i];
			dp[i][1] = maximo[i];
		} else {
			tint s = (tint)columnas.size();
			tint idxLeftMax = binarySearch(columnas, s, maximo[i-1], true);
			tint idxRightMax = binarySearch(columnas, s, maximo[i-1], false);
			tint idxLeftMin = binarySearch(columnas, s, minimo[i-1], true);
			tint idxRightMin = binarySearch(columnas, s, minimo[i-1], false);
			cout << idxLeftMin <<" " << idxLeftMax << " " <<idxRightMin << " " << idxRightMax << endl;
			idxLeftMax = columnas[idxLeftMax];
			idxLeftMin = columnas[idxLeftMin];
			idxRightMax = columnas[idxRightMax];
			idxRightMin = columnas[idxRightMin];

			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxRightMax) + abs(idxRightMax - minimo[i]) + 2*(idxRightMax < maximo[i])*abs(maximo[i] - idxRightMax));
			dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)  + abs(idxLeftMax - minimo[i])  + 2*(idxLeftMax < maximo[i])*abs(maximo[i] - idxLeftMax));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxRightMin) + abs(idxRightMin - minimo[i]) + 2*(idxRightMin < maximo[i])*abs(maximo[i] - idxRightMin));
			dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)  + abs(idxLeftMin - minimo[i])  + 2*(idxLeftMin < maximo[i])*abs(maximo[i] - idxLeftMin));

			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxRightMax)+ abs(idxRightMax - maximo[i]) + 2*(idxRightMax > minimo[i])*abs(minimo[i] - idxRightMax));
			dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(maximo[i-1] - idxLeftMax)+ abs(idxLeftMax - maximo[i]) + 2*(idxLeftMax > minimo[i])*abs(minimo[i] - idxLeftMax));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxRightMin)+ abs(idxRightMin - maximo[i]) + 2*(idxRightMin > minimo[i])*abs(minimo[i] - idxRightMin));
			dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(minimo[i-1] - idxLeftMin)+ abs(idxLeftMin - maximo[i]) + 2*(idxLeftMin > minimo[i])*abs(minimo[i] - idxLeftMin));
		}
	}
	//~ forn(i,n){
		//~ forn(l,2) cout << dp[i][l] << " ";
		//~ cout << endl;
	//~ }
	res += min(dp[n-1][0], dp[n-1][1]) + n-1;
	cout << res << endl;
	return 0;
}