#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
	char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(i < len && isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
	char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			if(s[i - 1] == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(i == 0 && s.substr(i , 3) == "...")
		{
			ans += "...";
			i += 2;
			continue;
		}
		bool b = true;
		while(i < s.size() && s[i] >= '0' && s[i] <= '9')
		{
			ans += s[i];
			i++;
			b = false;
		}
		if(!b && i < s.size() - 1)
		{
			ans += " ";
			i--;
			continue;
		}
		if(s[i] == ',')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			if(s[i - 1] == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(i == 0 && s.substr(i , 3) == "...")
		{
			ans += "...";
			i += 2;
			continue;
		}
		bool b = true;
		while(i < s.size() && s[i] >= '0' && s[i] <= '9')
		{
			ans += s[i];
			i++;
			b = false;
		}
		if(!b && i < s.size())
		{
			if(s[i] != ',' && s[i] != ' ')
				ans += " ";
			i--;
			continue;
		}
		if(s[i] == ',')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	char bef;
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			//cout << bef << endl;
			if(bef == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(i == 0 && s.substr(i , 3) == "...")
		{
			ans += "...";
			i += 2;
			continue;
		}
		bool b = true;
		while(i < s.size() && s[i] >= '0' && s[i] <= '9')
		{
			ans += s[i];
			i++;
			b = false;
		}
		if(!b && i < s.size())
		{
			while(s[i] == ' ' && i < s.size())
			{
				i++;
			}
			if(s[i] != ',' && s[i] != '.') // :////
				ans += " ";
			i--;
			continue;
		}
		if(s[i] == ',')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
		if(s[i] != ' ')
			bef = s[i];
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			if(s[i - 1] == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(s[i] != ' ')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			if(s[i - 1] == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(i == 0 && s.substr(i , 3) == "...")
		{
			ans += "...";
			i += 2;
			continue;
		}
		if(s[i] != ' ')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	getline(cin , s);
	char bef;
	string ans = "";
	for(int i = 0; i < s.size() ; i++)
	{
		if(i <= s.size() - 3 && i != 0 && s.substr(i , 3) == "...")
		{
			//cout << bef << endl;
			if(bef == ',')
			{
				ans += "...";
				i += 2;
				continue;
			}
			ans += " ...";
			i += 2;
			continue;
		}
		if(i == 0 && s.substr(i , 3) == "...")
		{
			ans += "...";
			i += 2;
			continue;
		}
		bool b = true;
		while(i < s.size() && s[i] >= '0' && s[i] <= '9')
		{
			if(s[i] != ' ')
				bef = s[i];
			ans += s[i];
			i++;
			b = false;
		}
		if(!b && i < s.size())
		{
			while(s[i] == ' ' && i < s.size())
			{
				i++;
			}
			if(s[i] != ',' && s[i] != '.') // :////
				ans += " ";
			i--;
			continue;
		}
		if(s[i] == ',')
			ans += s[i];
		if(s[i] == ',' && i != s.size() - 1)
			ans += " ";
		if(s[i] != ' ')
			bef = s[i];
	}
	cout << ans;
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

char buffer[1024];
void run(const int &caseID)
{
    vector<string> vs;

    string s="";

    gets(buffer);
    for(int i=0;buffer[i];++i)
    {
        char c=buffer[i];

        if(c==' ')
        {
            if(s!="")
                vs.PB(s);
            s="";
        }
        else if(c==',')
        {
            s+=',';
            vs.PB(s);
            s="";
        }
        else if(c=='.')
        {
            if(s!="" && s!="." && s!="..")
            {
                vs.PB(s);
                s="";
            }
            s+=c;
        }
        else
            s+=c;
    }
    if(s!="")
        vs.PB(s);

    for(int i=0;i<SIZE(vs);++i)
    {
        cout<<vs[i];
        if(i+1<SIZE(vs) && vs[i]!="," && vs[i+1]==",")
        {
            ++i;
            cout<<vs[i];
        }
        if(i+1==SIZE(vs))
            putchar('\n');
        else
            putchar(' ');
    }
}

int main(int argc, char *argv[])
{
    //READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

vector<string> split(const char s[])
{
    vector<string> vs;

    string terms="";
    for(int i=0;s[i];++i)
    {
        if(s[i]==' ')
        {
            if(terms!="")
                vs.PB(terms);
            terms="";
        }
        else if(s[i]==',')
        {
            if(terms!="")
                vs.PB(terms);
            terms="";
            vs.PB(",");
        }
        else if(s[i]=='.')
        {
            if(terms=="" || terms=="." || terms=="..")
            {
                terms+=s[i];
                if(terms=="...")
                {
                    vs.PB(terms);
                    terms="";
                }
            }
            else
            {
                if(terms!="")
                    vs.PB(terms);
                terms="";
                terms+=s[i];
            }
        }
        else
        {
            if(terms!="" || s[i]!='0')
                terms+=s[i];
        }
    }
    if(terms!="")
        vs.PB(terms);
    return vs;
}

char buffer[1024];
void run(const int &caseID)
{
    gets(buffer);
    vector<string> vs=split(buffer);
    for(int i=0;i<SIZE(vs);++i)
    {
        if(vs[i]==",")
        {
            cout<<vs[i];
            if(i+1!=SIZE(vs))
                cout<<' ';
        }
        else if(vs[i]=="...")
        {
            if(i!=0)
                cout<<' ';
            cout<<vs[i];
        }
        else
        {
            if(i!=0 && vs[i-1]!="," && vs[i-1]!="...")
                cout<<' ';
            cout<<vs[i];
        }
    }
    cout<<endl;
}

int main(int argc, char *argv[])
{
    READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

char buffer[1024];
void run(const int &caseID)
{
    vector<string> vs;

    string s="";

    gets(buffer);
    for(int i=0;buffer[i];++i)
    {
        char c=buffer[i];

        if(c==' ')
        {
            if(s!="")
                vs.PB(s);
            s="";
        }
        else if(c==',')
        {
            if(s!="")
                vs.PB(s);
            s="";
            s+=',';
            vs.PB(s);
            s="";
        }
        else if(c=='.')
        {
            if(s!="" && s!="." && s!="..")
            {
                vs.PB(s);
                s="";
            }
            s+=c;
        }
        else
            s+=c;
    }
    if(s!="")
        vs.PB(s);

    for(int i=0;i<SIZE(vs);++i)
    {
        cout<<vs[i];
        if(i+1<SIZE(vs) && vs[i]!="," && vs[i+1]==",")
        {
            ++i;
            cout<<vs[i];
        }
        if(i+1==SIZE(vs))
            putchar('\n');
        else
            putchar(' ');
    }
}

int main(int argc, char *argv[])
{
    //READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

vector<string> split(const char s[])
{
    vector<string> vs;

    string terms="";
    for(int i=0;s[i];++i)
    {
        if(s[i]==' ')
        {
            if(terms!="")
                vs.PB(terms);
            terms="";
        }
        else if(s[i]==',')
        {
            if(terms!="")
                vs.PB(terms);
            terms="";
            vs.PB(",");
        }
        else if(s[i]=='.')
        {
            if(terms=="" || terms=="." || terms=="..")
            {
                terms+=s[i];
                if(terms=="...")
                {
                    vs.PB(terms);
                    terms="";
                }
            }
            else
            {
                if(terms!="")
                    vs.PB(terms);
                terms="";
                terms+=s[i];
            }
        }
        else
        {
            if(terms!="" || s[i]!='0')
                terms+=s[i];
        }
    }
    if(terms!="")
        vs.PB(terms);
    return vs;
}

char buffer[1024];
void run(const int &caseID)
{
    gets(buffer);
    vector<string> vs=split(buffer);
    for(int i=0;i<SIZE(vs);++i)
    {
        if(vs[i]==",")
        {
            cout<<vs[i];
            if(i+1!=SIZE(vs))
                cout<<' ';
        }
        else if(vs[i]=="...")
        {
            if(i!=0 && vs[i-1]!=",")
                cout<<' ';
            cout<<vs[i];
        }
        else
        {
            if(i!=0 && vs[i-1]!="," && vs[i-1]!="...")
                cout<<' ';
            cout<<vs[i];
        }
    }
    cout<<endl;
}

int main(int argc, char *argv[])
{
    READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

char buffer[1024];
void run(const int &caseID)
{
    vector<string> vs;

    string s="";

    gets(buffer);
    for(int i=0;buffer[i];++i)
    {
        char c=buffer[i];

        if(c==' ')
        {
            if(s!="")
                vs.PB(s);
            s="";
        }
        else if(c==',')
        {
            s+=',';
            vs.PB(s);
            s="";
        }
        else if(c=='.')
        {
            if(s!="" && s!="." && s!="..")
            {
                vs.PB(s);
                s="";
            }
            s+=c;
        }
        else
            s+=c;
    }
    if(s!="")
        vs.PB(s);

    for(int i=0;i<SIZE(vs);++i)
    {
        cout<<vs[i];
        if(i+1==SIZE(vs))
            putchar('\n');
        else
            putchar(' ');
    }
}

int main(int argc, char *argv[])
{
    //READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

char buffer[1024];
void run(const int &caseID)
{
    vector<string> vs;

    string s="";

    gets(buffer);
    for(int i=0;buffer[i];++i)
    {
        char c=buffer[i];

        if(c==' ')
            continue;
        if(c==',')
        {
            s+=',';
            vs.PB(s);
            s="";
        }
        else if(c=='.')
        {
            if(s!="" && s!="." && s!="..")
            {
                vs.PB(s);
                s="";
            }
            s+=c;
        }
        else
            s+=c;
    }
    if(s!="")
        vs.PB(s);

    for(int i=0;i<SIZE(vs);++i)
    {
        cout<<vs[i];
        if(i+1==SIZE(vs))
            putchar('\n');
        else
            putchar(' ');
    }
}

int main(int argc, char *argv[])
{
    //READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

// Begin Template By yaymao

#ifndef ONLINE_JUDGE
    #define READ freopen("in","r",stdin)
    #define WRITE freopen("out","w",stdout)
#else
    #define READ
    #define WRITE
#endif

#ifdef _MSC_VER
    #define LL __int64
    #define ULL unsigned __int64
#else
    #define LL long long
    #define ULL unsigned long long
#endif

#define EPS 1E-9
#define D_INF 1E99
#define I_INF 0x7FFFFFFF
#define L_INF 0x7FFFFFFFFFFFFFFFLL

#define SIZE(x) ((int)x.size())
#define LENGTH(x) ((int)x.length())

#define X first
#define Y second
#define IMAP map<int,int>
#define SMAP map<int,int>
#define IPAIR pair<int,int>
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

#define TWO(x)          (1<<(x))
#define TWOL(x)         (1LL<<(x))
#define LOWER_BIT(x)    ((x)&(-(x)))
#define CONTAIN(s,x)    (((s)&TWO(x))!=0)
#define CONTAINL(s,x)   (((s)&TWOL(x))!=0)

template<class T>inline void checkMax(T &a,const T &b){if(a<b) a=b;}
template<class T>inline void checkMin(T &a,const T &b){if(b<a) a=b;}
template<class T>inline string toString(const T &n){ostringstream out;out<<n;out.flush();return out.str();}
template<class T>inline T toValue(const string &s){T x;istringstream in(s);in>>x;return x;}
bool hasNext(){char c;if(scanf(" %c",&c)==EOF) return false;ungetc(c,stdin);return true;}

int dx[]={ 0, 0,-1, 1,-1, 1,-1, 1};
int dy[]={-1, 1, 0, 0,-1,-1, 1, 1};
string dir[]={"L","R","U","D","LU","LD","RU","RD"};

int twoPower[32]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000,0x10000000,0x20000000,0x40000000,0x80000000};
int tenPower[10]={0x1,0xA,0x64,0x3E8,0x2710,0x186A0,0xF4240,0x989680,0x5F5E100,0x3B9ACA00};

// End Template By yaymao

char buffer[1024];
void run(const int &caseID)
{
    vector<string> vs;

    string s="";

    gets(buffer);
    for(int i=0;buffer[i];++i)
    {
        char c=buffer[i];

        if(c==' ')
        {
            if(s!="")
                vs.PB(s);
            s="";
        }
        else if(c==',')
        {
            s+=',';
            vs.PB(s);
            s="";
        }
        else if(c=='.')
        {
            if(s!="" && s!="." && s!="..")
            {
                vs.PB(s);
                s="";
            }
            s+=c;
        }
        else
            s+=c;
    }
    if(s!="")
        vs.PB(s);

    for(int i=0;i<SIZE(vs);++i)
    {
        cout<<vs[i];
        if(i+1<SIZE(vs) && vs[i+1]==",")
        {
            ++i;
            cout<<vs[i];
        }
        if(i+1==SIZE(vs))
            putchar('\n');
        else
            putchar(' ');
    }
}

int main(int argc, char *argv[])
{
    //READ;
    //WRITE;

    //int caseT;
    //scanf("%d",&caseT);

    int caseID=0;
    while(hasNext())
        run(++caseID);

    return (EXIT_SUCCESS);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=1;i<s.size()-1;i++)
		if(s[i]==' '&&isdigit(s[i-1])==isdigit(s[i+1])==1)
			while(isdigit(s[i+1])==1||s[i+1]==' ')
				s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			ans+=" ...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
	}
	if(ans[0]==' ')
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=1;i<s.size()-1;i++)
		if(s[i]==' '&&isdigit(s[i-1])==isdigit(s[i+1])==1)
			while(isdigit(s[i+1])==1||s[i+1]==' ')
				s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			if(s[i-1]!=',')
				ans+=" ...";
			else
				ans+="...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
	}
	if(ans[0]==' ')+2,
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=0;i<s.size()-2;i++)
		if(isdigit(s[i]))
		{
			while(isdigit(s[i]))
				i++;
			while(s[i]==' ')
				i++;
			if(isdigit(s[i]))
				s=s.substr(0,i)+'Z'+s.substr(i,s.size()-i);
	}
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			if(s[i-1]!=',')
				ans+=" ...";
			else
				ans+="...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
		if(s[i]=='Z')
			ans+=" ";
	}
	if(ans[0]==' ')+2,
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=1;i<s.size()-1;i++)
		if(s[i]==' '&&isdigit(s[i-1])==isdigit(s[i+1])==1)
			while(isdigit(s[i+1])==1||s[i+1]==' ')
				s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			ans+=" ...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
	}
	for(int i=0;i<s.size()-1;i++)
		if(ans[i]==' '&&ans[i+1]==' ')
			ans=ans.substr(0,i)+ans.substr(i+1,ans.size()-i-1);
	if(ans[0]==' ')+2,
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=0;i<s.size()-2;i++)
		if(isdigit(s[i]))
		{
			while(s[i+1]==' ')
				s=s.substr(0,i)+s.substr(i,s.size()-3);
			if(isdigit(s[i+1]))
				s=s.substr(0,i+2)+'Z'+s.substr(i+2,s.size()-i-2);
		}
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			if(s[i-1]!=',')
				ans+=" ...";
			else
				ans+="...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
		if(s[i]=='Z')
			ans+=" ";
	}
	if(ans[0]==' ')+2,
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	if(s.size()<2)
	{
		cout<<s;
		return 0;
	}
	for(int i=0;i<s.size()-2;i++)
		if(isdigit(s[i]))
		{
			while(isdigit(s[i]))
				i++;
			while(s[i]==' ')
				i++;
			if(isdigit(s[i]))
				s=s.substr(0,i)+'Z'+s.substr(i,s.size()-i);
		}
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			if(s[i-1]!=',')
				ans+=" ...";
			else
				ans+="...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
		if(s[i]=='Z')
			ans+=" ";
	}
	if(ans[0]==' ')+2,
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,ans="";
	getline(cin,s);
	for(int i=1;i<s.size()-1;i++)
		if(s[i]==' '&&isdigit(s[i-1])==isdigit(s[i+1])==1)
			while(isdigit(s[i+1])==1||s[i+1]==' ')
				s=s.substr(0,i+1)+s.substr(i+2,s.size()-i-2);
	for(int i=0;i<s.size();i++)
		if(s[i]==' ')
		{
			s=s.substr(0,i)+s.substr(i+1,s.size()-i-1);
			i--;
		}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
		{
			ans+=" ...";
			i+=2;
			continue;
		}
		if(isdigit(s[i]))
			ans+=s[i];
		if(s[i]==',')
			ans+=", ";
	}
	for(int i=0;i<s.size()-1;i++)
		if(s[i]==' '&&s[i+1]==' ')
		{
			s=s.substr(0,i-1)+s.substr(i+2,s.size()-i-1);
			i--;
			cout<<"bb";
		}
	if(ans[0]==' ')
		ans=ans.substr(1,ans.size()-1);
	if(ans[ans.size()-1]==' ')
		ans=ans.substr(0,ans.size()-1);
	cout<<ans;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=1003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (s[j]==' ' && j<n)j++;
			while (j<=n && isdigit(s[j])){
				erase(j);
			}
		}
	while (find(' ')!=0)erase(find(' '));
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i);
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=10003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	if (k<1 || k>n)return;
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=1003;

int n;
char s[maxn];

inline int find(char ch){
    int i;
    for1(i,1,n)
        if (s[i]==ch)return i;
    return 0;
}

inline void erase(int k){
    int i;
    for1(i,k,n-1)s[i]=s[i+1];
    n--;
}

inline void insert(int k,char ch){
    int i;
    for2(i,n,k)s[i+1]=s[i];
    n++;
    s[k]=ch;
}

int main(){
    n=0;
    char ch=getchar();
    while (ch!='\n' && ch!=-1){
        s[++n]=ch;
        ch=getchar();
    }
    int i,j;
    for1(i,1,n)
        if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
            j=i+1;
            while (s[j]==' ' && j<n)j++;
            while (j<=n && (isdigit(s[j]) || s[j]==' ')){
                erase(j);
            }
        }
    while (find(' ')!=0)erase(find(' '));
    for1(i,1,n)
        if (s[i]==',' && i!=n)insert(i+1,' ');
    for1(i,1,n){
        if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
            if (i!=1){
                insert(i,' ');
                i++;
            }
            i+=2;
        }
    }
    for1(i,1,n-1)
        if (s[i]==' ' && s[i+1]==' ')erase(i);
    for1(i,1,n)putchar(s[i]);
    puts("");
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=10003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	if (k<1 || k>n)return;
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n)
		if (s[i]==' ' && (i==1 || !isdigit(s[i-1]) || i==n || !isdigit(s[i+1])))erase(i),i--;
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=10003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!=-1){
		if (ch!='\n')s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (s[j]==' ' && j<n)j++;
			while (j<=n && (isdigit(s[j]) || s[j]==' ')){
				erase(j);
			}
		}
	while (find(' ')!=0)erase(find(' '));
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=1003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (s[j]==' ' && j<n)j++;
			while (j<=n && (isdigit(s[j]) || s[j]==' ')){
				erase(j);
			}
		}
	while (find(' ')!=0)erase(find(' '));
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=1003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	/*for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (s[j]==' ' && j<n)j++;
			while (j<=n && (isdigit(s[j]) || s[j]==' ')){
				erase(j);
			}
		}*/
	while (find(' ')!=0)erase(find(' '));
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i);
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=10003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	if (k<1 || k>n)return;
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	//freopen("x.in","r",stdin);
	//freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (j<=n && (isdigit(s[j]) || s[j]==' ')){
				erase(j);
			}
		}
	while (find(' ')!=0)erase(find(' '));
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

#define for1(i,a,b) for(i=a;i<=b;i++)
#define for2(i,a,b) for(i=a;i>=b;i--)

using namespace std;

const int maxn=10003;

int n;
char s[maxn];

inline int find(char ch){
	int i;
	for1(i,1,n)
		if (s[i]==ch)return i;
	return 0;
}

inline void erase(int k){
	if (k<1 || k>n)return;
	int i;
	for1(i,k,n-1)s[i]=s[i+1];
	n--;
}

inline void insert(int k,char ch){
	int i;
	for2(i,n,k)s[i+1]=s[i];
	n++;
	s[k]=ch;
}

int main(){
	freopen("x.in","r",stdin);
	freopen("x.out","w",stdout);
	n=0;
	char ch=getchar();
	while (ch!='\n' && ch!=-1){
		s[++n]=ch;
		ch=getchar();
	}
	int i,j;
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)
		if (s[i]==' ' && i!=1 && isdigit(s[i-1])){
			j=i+1;
			while (j<=n && (isdigit(s[j]) || s[j]==' ')){
				erase(j);
			}
		}
	for1(i,1,n)
		if (s[i]==',' && i!=n)insert(i+1,' ');
	for1(i,1,n){
		if (i+2<=n && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
			if (i!=1){
				insert(i,' ');
				i++;
			}
			i+=2;
		}
	}
	for1(i,1,n-1)
		if (s[i]==' ' && s[i+1]==' ')erase(i),i--;
	for1(i,1,n)putchar(s[i]);
	puts("");
	return 0;
}


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

int main()
{
	char in[300];
	gets (in);

	char out[300];
	int i, j, outlen=0;

	for (i=0; in[i]; i++){
		if (in[i] == '.'){
			if (out[outlen-1] != ' ' && outlen != 0){
				out[outlen++] = ' ';
			}

			for (j=0; j<3; j++)
				out[outlen++] = '.';

			i += 2;
		}
		else if (in[i] == ','){
			out[outlen++] = ',';
			out[outlen++] = ' ';
		}
		else if (in[i] == ' '){

		}
		else{
			while ('0' <= in[i] && in[i] <= '9')
				out[outlen++] = in[i++];

			for (j=i; in[j]==' '; j++);

			if ('0' <= in[j] && in[j] <= '9')
				out[outlen++] = ' ';

			i--;
		}
	}

	if (out[outlen-1] == ' ')
		out[outlen-1] = '\0';
	else
		out[outlen] = '\0';

	puts (out);
	return 0;
}


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

char in[256], out[256];

int main()
{
	//char in[300];
	gets (in);

	//char out[1000];
	int i, j, outlen=0;

	for (i=0; in[i]; i++){
		if (in[i] == '.'){
			if (out[outlen-1] != ' ' && outlen != 0){
				out[outlen++] = ' ';
			}

			for (j=0; j<3; j++)
				out[outlen++] = '.';

			i += 2;
		}
		else if (in[i] == ','){
			out[outlen++] = ',';
			out[outlen++] = ' ';
		}
		else if (in[i] == ' '){

		}
		else{
			while ('0' <= in[i] && in[i] <= '9')
				out[outlen++] = in[i++];

			for (j=i; in[j]==' '; j++);

			if ('0' <= in[j] && in[j] <= '9')
				out[outlen++] = ' ';

			i--;
		}
	}

	if (out[outlen-1] == ' ')
		out[outlen-1] = '\0';
	else
		out[outlen] = '\0';

	puts (out);
	return 0;
}


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

int main()
{
	char in[300];
	gets (in);

	char out[300];
	int i, j, outlen=0;

	for (i=0; in[i]; i++){
		if (in[i] == '.'){
			if (out[outlen-1] != ' ' && outlen){
				out[outlen++] = ' ';
			}

			for (j=0; j<3; j++)
				out[outlen++] = '.';

			i += 2;
		}
		else if (in[i] == ','){
			out[outlen++] = ',';
			out[outlen++] = ' ';
		}
		else if (in[i] == ' '){

		}
		else{
			while ('0' <= in[i] && in[i] <= '9')
				out[outlen++] = in[i++];

			for (j=i; in[j]==' '; j++){
				continue;
			}

			if ('0' <= in[j] && in[j] <= '9')
				out[outlen++] = ' ';

			i--;
		}
	}

	if (out[outlen-1] == ' ')
		out[outlen-1] = '\0';
	else
		out[outlen] = '\0';

	puts (out);
	return 0;
}


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

int ip, n;
char s[100010];

bool next_token (string& res)
{
	if (ip == n)  return false;

	res = "";
	while (ip < n && s[ip] == ' ')  ip++;

	if (ip == n)  return false;

	if (s[ip] == ','){
		res = ",";
		ip++;
		return true;
	}

	if ('0' <= s[ip] && s[ip] <= '9'){
		while ('0' <= s[ip] && s[ip] <= '9')
			res += s[ip++];

		return true;
	}

	if (s[ip] == '.'){
		res = "...";
		ip += 3;
		return true;
	}
}

int main()
{
	gets (s);
	n = strlen (s);
	ip = 0;

	string st;
	next_token (st);

	cout << st.c_str();
	string prev=st;

	while (next_token (st)){
		if (prev == "," || st == "..." || ('0' <= st[0] && st[0] <= '9' && '0' <= prev[0] && prev[0] <= '9'))
			cout << ' ';

		cout << st.c_str();
		prev = st;
	}

	puts ("");
	return 0;
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Modified_GCD
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int a = Next();
            int b = Next();

            int g = Gcd(a, b);

            var nn = new List<int>();
            for (int i = 1; (long) i*i <= g; i++)
            {
                if (g%i == 0)
                {
                    nn.Add(i);
                    nn.Add(g/i);
                }
            }
            nn.Sort();

            int n = Next();
            for (int i = 0; i < n; i++)
            {
                int l = Next();
                int r = Next();

                int index = nn.BinarySearch(r);
                if (index < 0)
                    index = ~index - 1;

                if (index >= 0 && nn[index] >= l)
                {
                    writer.WriteLine(nn[index]);
                }
                else
                {
                    writer.WriteLine("-1");
                }
            }

            writer.Flush();
        }

        public static int Gcd(int a, int b)
        {
            return b == 0 ? a : Gcd(b, a%b);
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
				//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var b = input[1];
			var n = sr.NextInt32();
			var gcd = Gcd(a, b);
			var dividers = Dividers(gcd);
			dividers.Add(gcd);
			for (var i = 0; i < n; i++) {
				input = sr.ReadArray(Int32.Parse);
				var low = input[0];
				var high = input[1];
				var answ = -1;
				for (var j = 0; j < dividers.Count; j++) {
					if (dividers[j] >= low && dividers[j] <= high) {
						answ = Math.Max(dividers[j], answ);
					}
					var d = gcd / dividers[j];
					if (dividers[j] >= low && dividers[j] <= high)
					{
						answ = Math.Max(d, answ);
					}
				}

				sw.WriteLine(answ);
			}
		}

		private List<int> Dividers(int n)
		{
			var mid = Math.Sqrt(n);
			var list = new List<int>();
			for (var i = 2; i <= mid; i++) {
				if (n % i == 0) {
					list.Add(i);
				}
			}

			return list;
		}

		private int Gcd(int a, int b)
		{
			if (b == 0) {
				return a;
			}

			return Gcd(b, a % b);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
				//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var b = input[1];
			var n = sr.NextInt32();
			var gcd = Gcd(a, b);
			var dividers = Dividers(gcd);
			dividers.Add(gcd);
			for (var i = 0; i < n; i++) {
				input = sr.ReadArray(Int32.Parse);
				var low = input[0];
				var high = input[1];
				var answ = -1;
				for (var j = 0; j < dividers.Count; j++) {
					if (dividers[j] >= low && dividers[j] <= high) {
						answ = Math.Max(dividers[j], answ);
					}
					var d = gcd / dividers[j];
					if (d >= low && d <= high)
					{
						answ = Math.Max(d, answ);
					}
				}

				sw.WriteLine(answ);
			}
		}

		private List<int> Dividers(int n)
		{
			var mid = Math.Sqrt(n);
			var list = new List<int>();
			for (var i = 2; i <= mid; i++) {
				if (n % i == 0) {
					list.Add(i);
				}
			}

			return list;
		}

		private int Gcd(int a, int b)
		{
			if (b == 0) {
				return a;
			}

			return Gcd(b, a % b);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
				//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var b = input[1];
			var n = sr.NextInt32();
			var gcd = Gcd(a, b);
			for (var i = 0; i < n; i++) {
				input = sr.ReadArray(Int32.Parse);
				var low = input[0];
				var high = input[1];
				var answ = -1;
				while (low <= high) {
					var mid = (low + high) / 2;
					var d = gcd / mid;
					if (d * mid == gcd) {
						answ = mid;
						low = mid + 1;
					}
					else {
						if (d == 0) {
							high = mid - 1;
						}
						else {
							low = mid + 1;
						}
					}
				}

				sw.WriteLine(answ);
			}
		}

		private int Gcd(int a, int b)
		{
			if (b == 0) {
				return a;
			}

			return Gcd(b, a % b);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun gcd(a:Int, b:Int):Int {
    val c = a % b
    if (c == 0) return b
    return gcd(b, c)
}

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    val d = gcd(a, b)
    var number = d
    val div = mutableListOf<Int>()
    var divisor = 1
    while (divisor * divisor <= number) {
        if (number % divisor == 0) {
            div.add(divisor)
            if (divisor * divisor != number) {
                div.add(number / divisor)
            }
        }
        divisor++
    }
    val t = sc.nextInt()
    for (_i in 0 until t) {
        val low = sc.nextInt()
        val high = sc.nextInt()
        var ans = -1
        for (i in div) {
            if (i in low..high) {
                ans = maxOf(ans, i)
            }
        }
        println(ans)
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <tr1/unordered_map>
#include <tr1/unordered_set>

#define umap    tr1::unordered_map
#define uset    tr1::unordered_set
#define pv(i,n) ((i)>0?(i)-1:(n)-1)
#define nx(i,n) ((i)+1<(n)?(i)+1:0)
#define TT      template<typename T>
#define TAB     template<typename A,typename B>
#define ss(x)   cout<<"DEBUG : "#x" = "<<(x)<<"\n"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
TT T sqr(const T &x) { return x * x; }
TT T abs(const T &x) { return x < 0 ? -x : x; }
TT void mil(T &a, const T &b) { if (a > b) a = b;}
TT void mal(T &a, const T &b) { if (a < b) a = b;}
TT T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
TAB B conv(const A &i) { stringstream s; s << i; B o; s >> o; return o; }
TAB istream& operator >>(istream &i, pair<A, B> &p) { return i >> p.first >> p.second; }
TT void usort(vector<T> &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
TT pair<T, T> operator +(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first + b.first, a.second + b.second); }
TT pair<T, T> operator -(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first - b.first, a.second - b.second); }

void york() {
    int a, b, n;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }

    vector<int> d;
    int bound = sqrt(a + 0.5);
    for (int i = 1; i <= bound; ++i) {
        if (a % i == 0 && b % i == 0) {
            d.push_back(i);
            int j = a / i;
            if (b % j == 0) {
                d.push_back(j);
            }
        }
    }
    if (b % a == 0) {
        d.push_back(a);
    }
    usort(d);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        int x = *--upper_bound(d.begin(), d.end(), r);
        if (x < l) {
            x = -1;
        }
        cout << x << '\n';
    }
}

int main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false);
#else
    freopen("1.txt", "r", stdin);
#endif
    york();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <tr1/unordered_map>
#include <tr1/unordered_set>

#define umap    tr1::unordered_map
#define uset    tr1::unordered_set
#define pv(i,n) ((i)>0?(i)-1:(n)-1)
#define nx(i,n) ((i)+1<(n)?(i)+1:0)
#define TT      template<typename T>
#define TAB     template<typename A,typename B>
#define ss(x)   cout<<"DEBUG : "#x" = "<<(x)<<"\n"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
TT T sqr(const T &x) { return x * x; }
TT T abs(const T &x) { return x < 0 ? -x : x; }
TT void mil(T &a, const T &b) { if (a > b) a = b;}
TT void mal(T &a, const T &b) { if (a < b) a = b;}
TT T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
TAB B conv(const A &i) { stringstream s; s << i; B o; s >> o; return o; }
TAB istream& operator >>(istream &i, pair<A, B> &p) { return i >> p.first >> p.second; }
TT void usort(vector<T> &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
TT pair<T, T> operator +(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first + b.first, a.second + b.second); }
TT pair<T, T> operator -(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first - b.first, a.second - b.second); }

void york() {
    int a, b, n;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }

    vector<int> d;
    int bound = sqrt(a + 0.5);
    for (int i = 1; i <= bound; ++i) {
        if (a % i == 0 && b % i == 0) {
            d.push_back(i);
        }
    }
    if (b % a == 0 && d.back() != a) {
        d.push_back(a);
    }

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        int x = *--upper_bound(d.begin(), d.end(), r);
        if (x < l) {
            x = -1;
        }
        cout << x << '\n';
    }
}

int main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false);
#else
    freopen("1.txt", "r", stdin);
#endif
    york();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <tr1/unordered_map>
#include <tr1/unordered_set>

#define umap    tr1::unordered_map
#define uset    tr1::unordered_set
#define pv(i,n) ((i)>0?(i)-1:(n)-1)
#define nx(i,n) ((i)+1<(n)?(i)+1:0)
#define TT      template<typename T>
#define TAB     template<typename A,typename B>
#define ss(x)   cout<<"DEBUG : "#x" = "<<(x)<<"\n"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
TT T sqr(const T &x) { return x * x; }
TT T abs(const T &x) { return x < 0 ? -x : x; }
TT void mil(T &a, const T &b) { if (a > b) a = b;}
TT void mal(T &a, const T &b) { if (a < b) a = b;}
TT T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
TAB B conv(const A &i) { stringstream s; s << i; B o; s >> o; return o; }
TAB istream& operator >>(istream &i, pair<A, B> &p) { return i >> p.first >> p.second; }
TT void usort(vector<T> &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
TT pair<T, T> operator +(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first + b.first, a.second + b.second); }
TT pair<T, T> operator -(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.first - b.first, a.second - b.second); }

void york() {
    int a, b, n;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }

    vector<int> d;
    int bound = sqrt(a + 0.5);
    for (int i = 1; i <= bound; ++i) {
        if (a % i == 0) {
            if (b % i == 0) {
                d.push_back(i);
            }
            int j = a / i;
            if (b % j == 0) {
                d.push_back(j);
            }
        }
    }
    if (b % a == 0) {
        d.push_back(a);
    }
    usort(d);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        int x = *--upper_bound(d.begin(), d.end(), r);
        if (x < l) {
            x = -1;
        }
        cout << x << '\n';
    }
}

int main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false);
#else
    freopen("1.txt", "r", stdin);
#endif
    york();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define y1 dadada
#define pb push_back
#define mp make_pair
const int inf=1e9;
const int N=100004;
vector<int> v;
int a,b,n,l,r,ok,q;
main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>a>>b>>n;
    q=__gcd(a,b);
    for(int i=1;i*i<=q;i++){
        if(q%i==0){
            v.pb(i);
            if(i*i!=q)v.pb(q/i);
        }
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;++i){
        cin>>l>>r;
        ok=-1;
        for(int j=v.size()-1;j>=0;j--){
            if(l<=v[j]&&v[j]<=r)
                {ok=v[j];break;}
            if(v[j]<l)break;
        }
        cout<<ok<<"\n";
    }
}


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

#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define For(i,k,n) for(decltype(n) (i) = (k);(i)<(n);(i)++)
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear GCC compiler:
 * If my code doesn't compile, this doesn't mean it's wrong.
 * It just means that you don't understand what I want.
 * Here's my safety pig, I hope my code gets accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    V<int> divisors;
    int a,b,n,low,high,d = -1;
    cin>>a>>b;
    cin>>n;
    int mini = min(a,b);
    for(int i = 1;i<=mini;i++){
        if(a%i == 0 && b%i == 0)divisors.pb(i);
    }
    while(n--){
        cin>>low>>high;
        d = upper_bound(all(divisors),high) - divisors.begin() - 1;
        d = divisors[d];
        if(d<low)d = -1;
        cout<<d<<endl;
    }
    return 0;
}
/**/


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

#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define For(i,k,n) for(decltype(n) (i) = (k);(i)<(n);(i)++)
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear GCC compiler:
 * If my code doesn't compile, this doesn't mean it's wrong.
 * It just means that you don't understand what I want.
 * Here's my safety pig, I hope my code gets accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    V<int> divisors;
    int a,b,n,low,high,d = -1;
    cin>>a>>b;
    cin>>n;
    int mini = min(a,b);
    for(int i = 1;i<=mini;i++){
        if(a%i == 0 && b%i == 0)divisors.pb(i);
    }
    while(n--){
        cin>>low>>high;
        d = -1;
        for(int i = divisors.size()-1;i>=0;i--){
            if(divisors[i] >= low && divisors[i] <= high){
                d=divisors[i];
                break;
            }
        }
        cout<<d<<endl;
    }
    return 0;
}
/**/


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

#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define For(i,k,n) for(decltype(n) (i) = (k);(i)<(n);(i)++)
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear GCC compiler:
 * If my code doesn't compile, this doesn't mean it's wrong.
 * It just means that you don't understand what I want.
 * Here's my safety pig, I hope my code gets accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,n,low,high,d = -1;
	cin>>a>>b;
	cin>>n;
	while(n--){
		cin>>low>>high;
		d = -1;
		high = min(a,min(b,high));
		for(int i = low;i<=high;i++){
			if(a%i == 0 && b%i == 0)d=i;
		}
		cout<<d<<endl;
	}
 	return 0;
}
/**/


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

#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define For(i,k,n) for(decltype(n) (i) = (k);(i)<(n);(i)++)
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear GCC compiler:
 * If my code doesn't compile, this doesn't mean it's wrong.
 * It just means that you don't understand what I want.
 * Here's my safety pig, I hope my code gets accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    V<int> divisors;
    int a,b,n,low,high,d = -1;
    cin>>a>>b;
    cin>>n;
    if(a>b)swap(a,b);
    for(int i = 1;i*i<=a;i++){
        if(a%i == 0 && b%i == 0)divisors.pb(i);
        if(i*i!=a && a%i == 0 && b%(a/i) == 0)divisors.pb(a/i);
    }
    SORT(divisors);
    while(n--){
        cin>>low>>high;
        d = upper_bound(all(divisors),high) - divisors.begin() - 1;
        d = divisors[d];
        if(d<low)d = -1;
        cout<<d<<endl;
    }
    return 0;
}
/**/


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int maxN = 1000*1000 + 5;

main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b; cin >> a >> b;
    int n; cin >> n;
    int gc = __gcd(a, b);
    vector<int> div;
    for(int i = 1; i * i <= gc; i ++)
    {
	  if(gc % i == 0)
	  {
		div.push_back(i);
		if(i != gc / i)
		    div.push_back(gc / i);
	  }
    }
    sort(div.begin(), div.end());
    int lo, hi;
    for(int i = 0; i < n; i ++)
    {
	  cin >> lo >> hi;
	  int pos = lower_bound(div.begin(), div.end(), hi) - div.begin();
	  if(pos == div.size() || div[pos] > hi) pos --;
	  if(pos == -1 || div[pos] > hi || div[pos] < lo) { cout << "-1" << endl; continue;}
	  cout << div[pos] << endl;
    }
    return 0;

}


#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef pair<int, int> pii;

#define FOR(i, x, y) for(ll i=x; i<=y; i++)
#define FORD(i, x, y) for (ll i = x; i >= y; --i)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; --i)

#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define SZ(c) (int)(c).size()

#define CLEAR(x) memset(x,0,sizeof x)
#define FILL(x, v) memset(x,v,sizeof x)
#define COPY(from, to) memcpy(to, from, sizeof to)

#define pb push_back
#define mp make_pair
#define X first
#define Y second

const double eps = 1.0e-11;
const double pi = acos(-1.0);

int gcd(int a, int b) {
    while(a && b) {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

vector<int> d;
int n, l, r;

void solve() {
    scanf("%d%d", &l, &r);
    REPD(j, SZ(d)) {
        if (l <= d[j] && d[j] <= r) {
            cout << d[j] << endl;
            return;
        }
    }
    cout << "-1\n";
}

int main() {
    int a, b;
    cin >> a >> b;
    int g = gcd(a , b);
    for (int i = 1; i * i <= g; ++i) {
        if (g % i == 0) {
            d.push_back(i);
            d.push_back(g / i);
        }
    }

    SORT(d);
    scanf("%d", &n);
    REP(i, n) {
        solve();
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
int main()
{
    int gcd1,gcd2,n,low,high,ans[100004]={0};
    cin>>gcd1>>gcd2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>low>>high;
        high=__gcd(low,high);
        for(int j=high;j>=low;j--){
            if(gcd1%j==0&&gcd2%j==0){ans[i]=j;break;}

        }if(ans[i]==0)ans[i]=-1;

    }
    for(int i=0;i<n;i++)cout<<ans[i]<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
int lista[100004]={0};
int main()
{
    int gcd1,gcd2,gcd,n,low,high,t=0,sum=-1;
    cin>>gcd1>>gcd2;
    gcd=__gcd(gcd1,gcd2);

    for(int i=1;i*i<=gcd;i++){
        if(gcd%i==0){lista[t++]=i;lista[t++]=gcd/i;}
    }
    sort(lista,lista+t,greater<int>());

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>low>>high;
        sum=-1;
        for(int j=0;j<t;j++){

            if(lista[j]>=low&&lista[j]<=high){sum=lista[j];break;}

        }
        printf("%d\n",sum);

    }

    return 0;
}


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

using namespace std;
int main()
{
    int gcd1,gcd2,n,low,high,ans[100004]={0};
    cin>>gcd1>>gcd2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>low>>high;

        for(int j=high;j>=low;j--){
            if(gcd1%j==0&&gcd2%j==0){ans[i]=j;break;}

        }if(ans[i]==0)ans[i]=-1;

    }
    for(int i=0;i<n;i++)cout<<ans[i]<<endl;

    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
long long gcd(long long,long long);
int main()
{long long a,b,u,i,v,x[100000],w,n,j,c,d,y;
cin>>a>>b;
u=gcd(a,b);
v=sqrt(u);
w=0;
for(i=1;i<=v;i++)
{if((u%i)==0){x[w]=i;w=w+1;
if(i!=(u/i)){x[w]=(u/i);w=w+1;}}}
cin>>n;
for(j=0;j<n;j++)
{cin>>c>>d;
y=-1;
for(i=0;i<w;i++)
{if((x[i]>=c)&&(x[i]<=d)&&(y<x[i]))
y=x[i];}
cout<<y<<"\n";}
return(0);}
long long gcd(long long a,long long b)
{long long u,v,w;
if(a<=b){u=b;v=a;
}else{u=a;v=b;}
while(1){
w=(u%v);
if(w==0) break;
u=v; v=w;}
return(v);
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

const int N = 40005;

#define rep(i,a,b) for(int i = a, _b = b; i < _b; ++i)

const int MOD = 1000000007;

int prime[N];
int np;

bool vis[N];

int get_prime(){
    np = 0;
    memset(vis, 0, sizeof(vis));
    for(int i = 2; i < N; ++i){
        if(!vis[i]) prime[np++] = i;
        for(int j = 0,t; j < np && (t = prime[j]*i) < N; ++j){
            vis[t] = 1;
            if(i % prime[j] == 0) break;
        }
    }
}

int gcd(int a,int b){
    return b? gcd(b,a%b):a;
}

int a,b,d;
int n;
vector<int> fac;

void get_fac(int v){
    fac.clear();
    for(int i = 1; i*i <= v; ++i){
        if(v % i == 0) fac.push_back(i), fac.push_back(v/i);
    }
    sort(fac.begin(), fac.end());
}

int Ans(int l,int r){
    int p = upper_bound(fac.begin(), fac.end(), r) - fac.begin();
    --p;
    if(p < 0 || fac[p] < l) return -1;
    return fac[p];
}

int main(){
    while(cin >> a >> b){
        d = gcd(a,b);
        get_fac(d);
        cin >> n;
        int l , r;
        for(int i = 0; i < n; ++i){
            scanf("%d%d",&l,&r);
            printf("%d\n", Ans(l, r));
        }
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <math.h>
#include <cmath>
#include <string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include <list>
#include <functional>
#include <sstream>
#include <fstream>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>     /* atoi */
#include <bitset>
#include <utility>
#include <cctype>
#include <cstring>
#include <cctype>
#include <vector>
#include<valarray>
#include <map>
#include <set>
#include<complex>
#include<iomanip>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
typedef vector<int> vint;
typedef set<int> sint;
typedef long long ll;
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()),((v).end())
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)

ll gcd(ll a, ll b){
    ll c;
    while (a != 0){
        c = a;
        a = b%a;
        b = c;
    }
    return b;
}
int main(){
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
#endif
    //GCD(A,B) = GCD(B, A mod B)
    ll a, b, h, l;
    int n;
    cin >> a >> b >> n;
    a = gcd(b, a%b);
    b = sqrt(a);
    vector<int>factors;
    for (int i = 1; i <= b; i++)
    {
        if (a%i == 0){
            factors.push_back(i);
            factors.push_back(a/i);
        }
    }
    sort(factors.begin(), factors.end());
    ll ans ;
    while (n--)
    {
        cin >> l >> h;
        int m = upper_bound(factors.begin(), factors.end(), h) - factors.begin() - 1;
        ans = factors[m];
        if (l > ans) puts("-1");
        else printf("%d\n", ans);

    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
vector<int> factor;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int n;
	int G = __gcd(a,b);
	for(int i=1;i<=sqrt(G);i++){
		if(G%i!=0)continue;
		int j=G/i;
		factor.push_back(i);
		if(i!=j)factor.push_back(j);
	}
	sort(factor.begin(),factor.end());
	scanf("%d",&n);
	while(n--){
		int h,l;
		scanf("%d %d",&l,&h);
		vector<int>::iterator it = upper_bound(factor.begin(),factor.end(),h);
		if((it-1)!=factor.end() && (*(it-1)) >=l )printf("%d\n",(*(it-1)));
		else puts("-1");

	}
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
vector<int> factor;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int n;
	int G = __gcd(a,b);
	for(int i=1;i<=sqrt(G);i++){
		if(G%i!=0)continue;
		int j=G/i;
		factor.push_back(i);
		if(i!=j)factor.push_back(j);
	}
	sort(factor.begin(),factor.end());
	scanf("%d",&n);
	while(n--){
		int h,l;
		scanf("%d %d",&l,&h);
		vector<int>::iterator it = upper_bound(factor.begin(),factor.end(),h+1);
		if((it-1)!=factor.end() && (*(it-1)) >=l )printf("%d\n",(*(it-1)));
		else puts("-1");

	}
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
vector<int> factor;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int n;
	int G = __gcd(a,b);
	for(int i=1;i<=sqrt(G);i++){
		if(G%i!=0)continue;
		int j=G/i;
		factor.push_back(i);
		if(i!=j)factor.push_back(j);
	}
	sort(factor.begin(),factor.end());
	for(int i=0;i<factor.size();i++)printf("%d ",factor[i]);puts("");
	scanf("%d",&n);
	while(n--){
		int h,l;
		scanf("%d %d",&l,&h);
		vector<int>::iterator it = upper_bound(factor.begin(),factor.end(),h+1);
		if((it-1)!=factor.end() && (*(it-1)) >=l )printf("%d\n",(*(it-1)));
		else puts("-1");

	}
}


/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <nlehmann@dcc.uchile.cl> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Nicolás Lehmann
 * ----------------------------------------------------------------------------
 */

#include <vector>
#include <iostream>
#include <algorithm>
int N = 100000;
std::vector<bool> sieve(N+1, true);
std::vector<int> primes;

std::vector<std::pair<int, int>> f;

void factorize(int n) {
  for (int p : primes) {
    int alfa = 0;
    while (n % p == 0) {
      n /= p;
      alfa++;
    }
    if (alfa > 0)
      f.emplace_back(p, alfa);
  }

  if (n > 1)
    f.emplace_back(n, 1);
}

std::vector<int> dividers;
void getDividers(int i, int d) {
  if (i == f.size()) {
    dividers.push_back(d);
    return;
  }

  int p = 1;
  for (int j = 0; j <= f[i].second; j++) {
    getDividers(i+1, d*p);
    p *= f[i].first;
  }

}

template<typename T, typename Fun>
int bs(std::vector<T> vec, Fun pred) {
  int left = 0;
  int right = vec.size();
  while (left < right) {
    int mid = (left + right)/2;
    if (pred(vec[mid]))
      right = mid;
    else
      left = mid + 1;
  }

  return left;
}

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

int main() {

  primes.push_back(2);
  for (int i = 4; i <= N; i += 2)
    sieve[i] = false;

  for (int64_t i = 3; i <= N; i += 2)
    if (sieve[(int) i]) {
      primes.push_back(i);
      for (int64_t j = i*i; j <= N; j += i)
        sieve[(int) j] = false;
    }

  int a,b;
  std::cin >> a >> b;

  int g = gcd(a,b);
  factorize(g);
  getDividers(0, 1);

  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int l,h;
    std::cin >> l >> h;

    int projl = bs(dividers, [&] (int x) {
      return x >= l;
    });
    int projh = bs(dividers, [&] (int x) {
      return x > h;
    });
    projh--;

    if (projl <= projh)
      std::cout << dividers[projh] << "\n";
    else
      std::cout << "-1\n";
  }

  return 0;
}


/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <nlehmann@dcc.uchile.cl> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Nicolás Lehmann
 * ----------------------------------------------------------------------------
 */

#include <vector>
#include <iostream>
#include <algorithm>
int N = 10000;
std::vector<bool> sieve(N+1, true);
std::vector<int> primes;

std::vector<std::pair<int, int>> f;

void factorize(int n) {
  for (int p : primes) {
    int alfa = 0;
    while (n % p == 0) {
      n /= p;
      alfa++;
    }
    if (alfa > 0)
      f.emplace_back(p, alfa);
  }

  if (n > 1)
    f.emplace_back(n, 1);
}

std::vector<int> dividers;
void getDividers(int i, int d) {
  if (i == f.size()) {
    dividers.push_back(d);
    return;
  }

  int p = 1;
  for (int j = 0; j <= f[i].second; j++) {
    getDividers(i+1, d*p);
    p *= f[i].first;
  }

}

template<typename T, typename Fun>
int bs(std::vector<T> vec, Fun pred) {
  int left = 0;
  int right = vec.size();
  while (left < right) {
    int mid = (left + right)/2;
    if (pred(vec[mid]))
      right = mid;
    else
      left = mid + 1;
  }

  return left;
}

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

int main() {

  primes.push_back(2);
  for (int i = 4; i <= N; i += 2)
    sieve[i] = false;

  for (int i = 3; i <= N; i += 2)
    if (sieve[i]) {
      primes.push_back(i);
      for (int j = i*i; j <= N; j += i)
        sieve[j] = false;
    }

  int a,b;
  std::cin >> a >> b;

  int g = gcd(a,b);
  factorize(g);
  getDividers(0, 1);

  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int l,h;
    std::cin >> l >> h;

    int projl = bs(dividers, [&] (int x) {
      return x >= l;
    });
    int projh = bs(dividers, [&] (int x) {
      return x > h;
    });
    projh--;

    if (projl <= projh)
      std::cout << dividers[projh] << "\n";
    else
      std::cout << "-1\n";
  }

  return 0;
}


/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <nlehmann@dcc.uchile.cl> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Nicolás Lehmann
 * ----------------------------------------------------------------------------
 */

#include <vector>
#include <iostream>
#include <algorithm>
int N = 1000;
std::vector<bool> sieve(N+1, true);
std::vector<int> primes;

std::vector<std::pair<int, int>> f;

void factorize(int n) {
  for (int p : primes) {
    int alfa = 0;
    while (n % p == 0) {
      n /= p;
      alfa++;
    }
    if (alfa > 0)
      f.emplace_back(p, alfa);
  }

  if (n > 1)
    f.emplace_back(n, 1);
}

std::vector<int> dividers;
void getDividers(int i, int d) {
  if (i == f.size()) {
    dividers.push_back(d);
    return;
  }

  int p = 1;
  for (int j = 0; j <= f[i].second; j++) {
    getDividers(i+1, d*p);
    p *= f[i].first;
  }

}

template<typename T, typename Fun>
int bs(std::vector<T> vec, Fun pred) {
  int left = 0;
  int right = vec.size();
  while (left < right) {
    int mid = (left + right)/2;
    if (pred(vec[mid]))
      right = mid;
    else
      left = mid + 1;
  }

  return left;
}

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

int main() {

  primes.push_back(2);
  for (int i = 4; i <= N; i += 2)
    sieve[i] = false;

  for (int i = 3; i <= N; i += 2)
    if (sieve[i]) {
      primes.push_back(i);
      for (int j = i*i; j <= N; j += i)
        sieve[j] = false;
    }

  int a,b;
  std::cin >> a >> b;

  int g = gcd(a,b);
  factorize(g);
  getDividers(0, 1);

  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int l,h;
    std::cin >> l >> h;

    int projl = bs(dividers, [&] (int x) {
      return x >= l;
    });
    int projh = bs(dividers, [&] (int x) {
      return x > h;
    });
    projh--;

    if (projl <= projh)
      std::cout << dividers[projh] << "\n";
    else
      std::cout << "-1\n";
  }

  return 0;
}


/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <nlehmann@dcc.uchile.cl> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Nicolás Lehmann
 * ----------------------------------------------------------------------------
 */

#include <vector>
#include <iostream>
#include <algorithm>
int N = 100000;
std::vector<bool> sieve(N+1, true);
std::vector<int> primes;

std::vector<std::pair<int, int>> f;

void factorize(int n) {
  for (int p : primes) {
    int alfa = 0;
    while (n % p == 0) {
      n /= p;
      alfa++;
    }
    if (alfa > 0)
      f.emplace_back(p, alfa);
  }

  if (n > 1)
    f.emplace_back(n, 1);
}

std::vector<int> dividers;
void getDividers(int i, int d) {
  if (i == f.size()) {
    dividers.push_back(d);
    return;
  }

  int p = 1;
  for (int j = 0; j <= f[i].second; j++) {
    getDividers(i+1, d*p);
    p *= f[i].first;
  }

}

template<typename T, typename Fun>
int bs(std::vector<T> vec, Fun pred) {
  int left = 0;
  int right = vec.size();
  while (left < right) {
    int mid = (left + right)/2;
    if (pred(vec[mid]))
      right = mid;
    else
      left = mid + 1;
  }

  return left;
}

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

int main() {

  primes.push_back(2);
  for (int i = 4; i <= N; i += 2)
    sieve[i] = false;

  for (int64_t i = 3; i <= N; i += 2)
    if (sieve[(int) i]) {
      primes.push_back(i);
      for (int64_t j = i*i; j <= N; j += i)
        sieve[(int) j] = false;
    }

  int a,b;
  std::cin >> a >> b;

  int g = gcd(a,b);
  factorize(g);
  getDividers(0, 1);
  std::sort(dividers.begin(), dividers.end());

  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int l,h;
    std::cin >> l >> h;

    int projl = bs(dividers, [&] (int x) {
      return x >= l;
    });
    int projh = bs(dividers, [&] (int x) {
      return x > h;
    });
    projh--;

    if (projl <= projh)
      std::cout << dividers[projh] << "\n";
    else
      std::cout << "-1\n";
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int a,b,n,g,s[100000]={0};
vi p,v,r;
set<int> st;

int gcd(int a,int b) {
    if (a<b) return gcd(b,a);
    while (a%b!=0) {
        int c=a%b;
        a=b;
        b=c;
    }
    return b;
}

void refill(int a,int b) {
    st.insert(a);
    FOR(i,b,v.size()) if (a%v[i]==0) refill(a/v[i],i);
}

int lookup (int l,int h,vi V) {

    for (int i=V.size()-1;i>-1;i--) {
        if ((V[i]>=l) && (V[i]<=h)) return V[i];
        else if (V[i]<l) return -1;
    }
    return -1;
}

int main() {
    FOR(i,2,100000) {
        if (s[i]==0) {
            p.pb(i);
            for (int j=i*2;j<100000;j+=i) s[j]=1;
        }
    }
    cin>>a>>b>>n;
    g=gcd(a,b);
    REP(i,p.size()) {
        if (g%p[i]==0) v.pb(p[i]);
    }
    p.clear();
    REP(i,v.size()) refill(g,i);
    vi V(st.begin(),st.end());
    SORT(V);
    cout<<endl;
    REP(i,V.size()) cout<<V[i]<<" ";
    cout<<endl;
    REP(i,n) {
        int l,h;
        cin>>l>>h;
        cout<<lookup(l,h,V);
    }
}


#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int a,b,n,g,s[100000]={0};
vi p,v,r;
set<int> st;

int gcd(int a,int b) {
    if (a<b) return gcd(b,a);
    while (a%b!=0) {
        int c=a%b;
        a=b;
        b=c;
    }
    return b;
}

void refill(int a,int b) {
    st.insert(a);
    FOR(i,b,v.size()) if (a%v[i]==0) refill(a/v[i],i);
}

int lookup (int l,int h,vi V) {

    for (int i=V.size()-1;i>-1;i--) {
        if ((V[i]>=l) && (V[i]<=h)) return V[i];
        else if (V[i]<l) return -1;
    }
    return -1;
}

int main() {
    FOR(i,2,100000) {
        if (s[i]==0) {
            p.pb(i);
            for (int j=i*2;j<100000;j+=i) s[j]=1;
        }
    }
    cin>>a>>b>>n;
    g=gcd(a,b);
    REP(i,p.size()) {
        if (g%p[i]==0) v.pb(p[i]);
    }
    p.clear();
    REP(i,v.size()) refill(g,i);
    vi V(st.begin(),st.end());
    SORT(V);
    REP(i,n) {
        int l,h;
        cin>>l>>h;
        cout<<lookup(l,h,V);
    }
}


#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int a,b,n,g,s[100000]={0};
vi p,v,r;
set<int> st;

int gcd(int a,int b) {
    if (a<b) return gcd(b,a);
    while (a%b!=0) {
        int c=a%b;
        a=b;
        b=c;
    }
    return b;
}

void refill(int a,int b) {
    st.insert(a);
    FOR(i,b,v.size()) if (a%v[i]==0) refill(a/v[i],i);
}

int lookup (int l,int h,vi V) {

    for (int i=V.size()-1;i>-1;i--) {
        if ((V[i]>=l) && (V[i]<=h)) return V[i];
        else if (V[i]<l) return -1;
    }
    return -1;
}

int main() {
    FOR(i,2,100000) {
        if (s[i]==0) {
            p.pb(i);
            for (int j=i*2;j<100000;j+=i) s[j]=1;
        }
    }
    cin>>a>>b>>n;
    g=gcd(a,b);
    REP(i,p.size()) {
        if (g%p[i]==0) v.pb(p[i]);
    }
    p.clear();
    REP(i,v.size()) refill(g,i);
    vi V(st.begin(),st.end());
    SORT(V);
    REP(i,n) {
        int l,h;
        cin>>l>>h;
        cout<<lookup(l,h,V)<<endl;
    }
}


#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int a,b,n,g,s[100000]={0};
vi p,v,r;
set<int> st;

int gcd(int a,int b) {
    if (a<b) return gcd(b,a);
    while (a%b!=0) {
        int c=a%b;
        a=b;
        b=c;
    }
    return b;
}

void refill(int a,int b) {
    st.insert(a);
    FOR(i,b,v.size()) if (a%v[i]==0) refill(a/v[i],i);
}

int lookup (int l,int h,vi V) {

    for (int i=V.size()-1;i>-1;i--) {
        if ((V[i]>=l) && (V[i]<=h)) return V[i];
        else if (V[i]<l) return -1;
    }
    return -1;
}

int main() {
    FOR(i,2,100000) {
        if (s[i]==0) {
            p.pb(i);
            for (int j=i*2;j<100000;j+=i) s[j]=1;
        }
    }
    cin>>a>>b>>n;
    g=gcd(a,b);
    REP(i,p.size()) {
        if (g%p[i]==0) v.pb(p[i]);
    }
    p.clear();
    st.insert(g);
    REP(i,v.size()) refill(g,i);
    vi V(st.begin(),st.end());
    SORT(V);
    REP(i,n) {
        int l,h;
        cin>>l>>h;
        cout<<lookup(l,h,V)<<endl;
    }
}