#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define sz(x)      x.size()
#define  nl       printf("\n")
#define lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define Sort(v) sort(v.begin(),v.end())
#define pi (2*acos(0))

ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
int n,m,u,v;
ll x,y;
ll l,r;
ll mn=imn;
ll p,q;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(t);
    wh(t){

        scl2(x,y);
        scl2(p,q);
        l=1ll,r=2000000000ll;
        mn=imn;

        if(x==p && q==y)
        {
            cout<<"0"<<endl;
            continue;
        }

        if(x!=0ll && p==0ll)
        {
            cout<<"-1"<<endl;
           continue;
        }
        if(x/p==y/q  && p!=0ll &&q!=0ll)
        {
             cout<<"0"<<endl;
            continue;
        }

     if(x==0ll  && p==0ll)
     {
         cout<<"0"<<endl;
       continue;
     }

        while(l<r)
        { // cout<<l<<r<<endl;
             ll mid=(l+r)/2ll;
             ll now=q*mid;
             now=now-y;
         // if(mid==2)

          // op(now);
          // op(now);

              if(now>0){
                   // op(now);
                  // op(mid);
                   //if(mid==6)
                   // op(now);

                 ll now1=mid*p;
                // op(now1);
               // if(mid==2)
                  //  op(now1);

              //op(mid);
              //if(mid==5)
               // op(now1);
                 if(now1-x<=now  && now1>=x)
                 { // if(mid==2)
               //  op(now1);
                    r=mid-1;
                    mn=min(mn,now);
                   // op(mid);
                   // op(mid);

                 }
                 else
                    l=mid+1;

              }
              else
                l=mid+1;

        }
      // op(l);

if(mn==imn)
    cout<<"-1"<<endl;
else
    cout<<mn<<endl;
    mn=imn;

}
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define sz(x)      x.size()
#define  nl       printf("\n")
#define lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define Sort(v) sort(v.begin(),v.end())
#define pi (2*acos(0))

ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
int n,m,u,v;
ll x,y;
ll l,r;
ll mn=imn;
ll p,q;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(t);
    wh(t){

        scl2(x,y);
        scl2(p,q);
        l=1ll,r=1000000000ll;
        mn=imn;

        if(x==p && q==y)
        {
            cout<<"0"<<endl;
            continue;
        }

        if(x/p==y/q  && p!=0 &&q!=0)
        {
             cout<<"0"<<endl;
            continue;
        }

     if(x==0  && p==0)
     {
         cout<<"0"<<endl;
         return 0;
     }

        while(l<=r)
        { // cout<<l<<r<<endl;
             ll mid=(l+r)/2ll;
             ll now=q*mid;
             now=now-y;
         // if(mid==2)

          // op(now);
          // op(now);

              if(now>0){
                   // op(now);
                  // op(mid);
                   //if(mid==6)
                   // op(now);

                 ll now1=mid*p;
                // op(now1);
               // if(mid==2)
                  //  op(now1);

              //op(mid);
              //if(mid==5)
               // op(now1);
                 if(now1-x<=now  && now1>=x)
                 { // if(mid==2)
               //  op(now1);
                    r=mid-1;
                    mn=min(mn,now);
                   // op(mid);
                   // op(mid);

                 }
                 else
                    l=mid+1;

              }
              else
                l=mid+1;

        }
      // op(l);

if(mn==imn)
    cout<<"-1"<<endl;
else
    cout<<mn<<endl;
    mn=imn;

}
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define sz(x)      x.size()
#define  nl       printf("\n")
#define lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define Sort(v) sort(v.begin(),v.end())
#define pi (2*acos(0))

ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
int n,m,u,v;
ll x,y;
ll l,r;
ll mn=imn;
ll p,q;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(t);
    wh(t){

        scl2(x,y);
        scl2(p,q);
        l=1ll,r=1000000000ll;
        mn=imn;

        if(x==p && q==y)
        {
            cout<<"0"<<endl;
            continue;
        }

        if(x/p==y/q  && p!=0 &&q!=0)
        {
             cout<<"0"<<endl;
            continue;
        }

        while(l<=r)
        { // cout<<l<<r<<endl;
             ll mid=(l+r)/2ll;
             ll now=q*mid;
             now=now-y;
         // if(mid==2)

          // op(now);
          // op(now);

              if(now>0){
                   // op(now);
                  // op(mid);
                   //if(mid==6)
                   // op(now);

                 ll now1=mid*p;
                // op(now1);
               // if(mid==2)
                  //  op(now1);

              //op(mid);
              //if(mid==5)
               // op(now1);
                 if(now1-x<=now  && now1>=x)
                 { // if(mid==2)
               //  op(now1);
                    r=mid-1;
                    mn=min(mn,now);
                   // op(mid);
                   // op(mid);

                 }
                 else
                    l=mid+1;

              }
              else
                l=mid+1;

        }
      // op(l);

if(mn==imn)
    cout<<"-1"<<endl;
else
    cout<<mn<<endl;
    mn=imn;

}
    return 0;

}


#include <cstdio>
#include <algorithm>
#define lld "%lld"
typedef long long lnt;
typedef void vnt;
const lnt LNF = 0x7F7F7F7F7F7F7F7FLL;
inline vnt gcd(lnt a, lnt b, lnt & x, lnt & y)
{
	if (!b) x = 1, y = 0;
	else gcd(b, a % b, y, x), y -= a / b * x;
}
inline lnt div(lnt a, lnt b)
{
	return a < 0 ? a / b : (a + b - 1) / b;
}
int T;
lnt m, n, p, q, w, x, y;
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf(lld lld lld lld, &m, &n, &p, &q);
		if (p == 0)
			printf("%d\n", m == 0 ? 0 : -1);
		else if (p == q)
			printf("%d\n", m == n ? 0 : -1);
		else
		{
			gcd(q, p, x, y);
			w = p * n - q * m, x *= w, y *= -w;
			printf(lld "\n", y + q * std::max(div(x - y, q - p), std::max(div(-x, p), div(-y, q))));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#define lld "%lld"
typedef long long lnt;
typedef void vnt;
const lnt LNF = 0x7F7F7F7F7F7F7F7FLL;
inline lnt div(lnt a, lnt b)
{
	return a < 0 ? a / b : (a + b - 1) / b;
}
inline vnt gcd(lnt a, lnt b, lnt & x, lnt & y)
{
	static lnt k;
	if (!b)
		x = 1, y = 0;
	else
	{
		gcd(b, a % b, y, x), y -= a / b * x;
		if (y < 0)
			k = div(-y, a), x -= k * b, y += k * a;
	}
}
int T;
lnt m, n, p, q, w, x, y;
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf(lld lld lld lld, &m, &n, &p, &q);
		if (p == 0)
			printf("%d\n", m == 0 ? 0 : -1);
		else if (p == q)
			printf("%d\n", m == n ? 0 : -1);
		else
		{
			gcd(q, p, x, y);
			w = p * n - q * m, x *= w, y *= -w;
			printf(lld "\n", y + q * std::max(div(x - y, q - p), std::max(div(-x, p), div(-y, q))));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#define lld "%lld"
typedef long long lnt;
typedef void vnt;
const lnt LNF = 0x7F7F7F7F7F7F7F7FLL;
int T;
lnt m, n, p, q;
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf(lld lld lld lld, &m, &n, &p, &q);
		if (p == 0)
			printf("%d\n", m == 0 ? 0 : -1);
		else if (p == q)
			printf("%d\n", m == n ? 0 : -1);
		else
			printf(lld "\n", std::max((m + p - 1) / p, (n - m + q - p - 1) / (q - p)) * q - n);
	}
	return 0;
}


#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

inline char gc()
{
		static const int L = 1000;
		static char sxd[L], *sss = sxd, *ttt = sxd;
		if(sss == ttt)
		{
				ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
				if(sss == ttt)
						return EOF;
		}
		return *sss++;
}

#define dd c = getchar()
inline long long read(long long& x)
{
		x = 0;
		char dd;
		bool f = false;
		for(; !isdigit(c); dd)
		{
				if(c == EOF)
						return -1;
				if(c == '-')
						f = true;
		}
		for(; isdigit(c); dd)
				x = (x << 1) + (x << 3) + (c ^ 48);
		if(f)
				x = -x;
		return 1;
}
#undef dd

long long t,x,y,p,q,l,r,m,ans,z;
int main()
{
	read(t);
	while(t--)
	{
		read(x);
		read(y);
		read(p);
		read(q);
		l=1;
		r=1e18/q;
		while(233)
		{
			m=(l+r)/2;
			if(l==m)
			{
				z=l*q-y;
				if((z>=0)&&((x+z)>=l*p)&&(x<=l*p))
				{
					ans=l;
				}
				else if(((r*q-y)>=0)&&((x+(r*q-y))>=r*p)&&(x<=r*p))
				{
					ans=r;
				}
				else
				{
					ans=-1;
				}
				break;
			}
			if(m*q<y)
			{
				l=m+1;
				continue;
			}
			z=m*q-y;
			if(((x+z)>=m*p)&&(x<=m*p)) r=m;
			  else l=m+1;
		}
		if(ans==-1) puts("-1");
		  else printf("%lld\n",ans*q-y);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (p == 1 && q == 1) {
            if (x != y) {
                puts("-1");
            } else {
                puts("0");
            }
            continue;
        }

        if (p == 0) {
            if (x == 0) {
                puts("0");
            } else {
                puts("-1");
            }
            continue;
        }

        ll ans = max({(y + q - 1) / q, (x + p - 1) / p, (y - x + q - p - 1) / (q - p)});
        printf("%lld\n", ans * q - y);
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (x != y && p == 1 && q == 1) {
            puts("-1");
            continue;
        }

        ll ans = max({(y + q - 1) / q, (x + p - 1) / p, (y - x + q - p - 1) / (q - p)});
        printf("%lld\n", ans * q - y);
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (x != y && p == 1 && q == 1) {
            puts("-1");
            continue;
        }

        ll minq = 0;
        if (p > 0) minq = (x + p - 1) / p;
        ll ans = max({(y + q - 1) / q, (x + p - 1) / p, (y - x + q - p - 1) / (q - p)});
        printf("%lld\n", ans * q - y);
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (x != y && p == 1 && q == 1) {
            puts("-1");
            continue;
        }

        ll minq = 0;
        if (p > 0) minq = (x + p - 1) / p;
        ll ans = max({(y + q - 1) / q, minq, (y - x + q - p - 1) / (q - p)});
        printf("%lld\n", ans * q - y);
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (x != y && p == 1 && q == 1) {
            puts("-1");
            continue;
        }

        ll lb = 0, rb = 1;
        while (rb * p < x || rb * q < y || rb * q - y < rb * p - x) rb *= 2;
        while (lb + 1 < rb) {
            ll mb = (lb + rb) / 2;
            if (mb * q >= y && mb * p >= x && mb * p - x <= mb * q - y) {
                rb = mb;
            } else {
                lb = mb;
            }
        }
        printf("%lld\n", rb * q - y);
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

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

int main() {
#if __APPLE__
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

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

    for (int it = 0; it < t; ++it) {
        ll x, y, p, q;
        scanf("%lld%lld%lld%lld", &x, &y, &p, &q);

        if (x != y && p == 1 && q == 1) {
            puts("-1");
            continue;
        }

        if (p == 0) {
            if (x == 0) {
                puts("0");
            } else {
                puts("-1");
            }
            continue;
        }

        ll ans = max({(y + q - 1) / q, (x + p - 1) / p, (y - x + q - p - 1) / (q - p)});
        printf("%lld\n", ans * q - y);
    }
}


#include <bits/stdc++.h>
using namespace std;
int64_t x,y,p,q,t,n,a;
int main(){
cin>>t;
for(;t--;){
	cin>>x>>y>>p>>q;
	if(q==p&&y!=x||!p&&x)a=-1;
	else if(q==p&&y==x||!p&&!x)a=0;
	else{
		y-=x;q-=p;
		n=max((x+p-1)/p,(y+q-1)/q);
		a=q*n-y+p*n-x;
	}
	cout<<a<<endl;
}
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i = 1;i <= t;i++){
        int x, y, p, q;
        cin >> x >> y >> p >> q;
        long long low = 0;
        long long high = 1e9 + 5;
        while(low < high){
            long long mid = (low + high) / 2;
            if(p*mid >= x && q*mid - p*mid >= y - x)
                high = mid;
            else low = mid + 1;
        }
        if(low > 1e9)cout << "-1" << "\n";
        else cout << p*low - x + (q*low - p*low) - (y - x) << "\n";
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<climits>
#include<map>
#include<set>
#include<utility>
#include<iterator>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define ff first
#define ss second
//#define scd static_cast<double>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using pill=pair<int,ll>;
using vvi=vector<vi>;

ll gcd(ll a, ll b)
{
	ll t;
	while((t=a%b)!=0) {
		a=b;
		b=t;
	}
	return b;
}

ll fast_exp(ll base, ll n, ll m)
{
	if(n==0)	return 1;
	ll t=fast_exp(base,n/2,m);
	if(n%2==0)	return (t*t)%m;
	else	return (((t*t)%m)*base)%m;
}

bool is_set(int i, ll mask)
{
	return (mask>>i)&1;
}

int count_bits(ll mask)
{
	int ans=0;
	for(int i=0;i<64;++i)
		if (is_set(i,mask)) ++ans;
	return ans;
}

int first_bit(ll mask)
{
	int i=0;
	while(i<64)
		if(is_set(i++, mask)) return i-1;
	return -1;
}

int main()
{
	ios::sync_with_stdio(false);
    int t;cin>>t;
    while (t--) {
        ll x, y, p, q;
        cin>>x>>y>>p>>q;
        if (p==0 and x != 0 || p==1 and q==1 and x!=y) {
            cout<<"-1\n";
            continue;
        }
        ll l=0, r=1e9;
        while (l<r) {
            ll m=l+(r-l)/2;
            if (p*m >= x and (q-p)*m >= y - x)
                r=m;
            else
                l=m+1;
        }
        cout<<q*l-y<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  int tt;
  cin >> tt;
  while (tt--)
  {
    int x,y,p,q;
    cin>>x>>y>>p>>q;
    if(p==0)
    {
      cout<<(x==0?0:-1)<<endl;
      continue;
    }
    if(p==q)
    {
      cout<<(x==y?0:-1)<<endl;
      continue;
    }
    int t1=(x+p-1)/p;
    int t2=((y-x)+(q-p)-1)/(q-p);
    cout << (q*1LL*max(t1,t2)-y)<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t,x,y,p,q,g;
  for(cin>>t;t--;)
  {
    cin>>x>>y>>p>>q;
    if(p==q)
    {
      if(x!=y) cout<<"-1\n";
      else cout<<"0\n";
    }
    else
    {
      if((y-x)%(q-p)) cout<<max((y%q==0)?y/q:y/q+1,(x%p==0)?x/p:x/p+1)*q-y<<endl;
      else cout<<(y-x)/(q-p)*q-y<<endl;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v)  (v.begin()),(v.end())
#define sc(n)   scanf("%lld",&n)
#define pr(n)   printf("%lld\n",n)
#define mk make_pair
typedef long long ll;
typedef vector<int>vi;
typedef unordered_map<int,pair<int,int>>mp;
typedef pair<int,int>pir;
typedef priority_queue<int>pq;
void file(){freopen("halfnice.in", "r", stdin);/*freopen("out.txt", "w", stdout);*/}
const int MAX=2e9+1, INF = (1<<30);

int main(){
    ll t,x,y,p,q,ans=0;
    sc(t);
    while(t--){
        scanf("%lld%lld%lld%lld",&x,&y,&p,&q);
        ll l=0,r=1e10,mid;
        while(l<r){
            mid=l+(r-l)/2;
            if(((p*mid)-x)<=((q*mid)-y)&&p*mid>=x&&q*mid>=y)
                r=mid,ans=((q*mid)-y);
            else
                l=mid+1;
        }
        if(!(((p*l)-x)<=((q*l)-y)&&p*l>=x&&q*l>=y))
            ans=-1;
        pr(ans);
    }
    return 0;
}


#include <iostream>
#include <limits>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long t;
    cin>>t;
    while(t--){
        long long x, y, p, q;
        cin>>x>>y>>p>>q;
        if(p == q){
            if(x == y)
                cout<<"0\n";
            else cout<<"-1\n";
            continue;
        }
        long long l = 1ll, r = 1000000000ll, m;
        while(l != r){
            m = (l + r)/2ll;
            if(((q * m - y) >= (p * m - x)) && ((q * m) >= y) && ((p * m) >= x))
                r = m;
            else l = m + 1;
        }
        if(!(((q * r - y) >= (p * r- x)) && ((q * r) >= y) && ((p * r) >= x))){
            cout<<-1<<'\n';
            continue;
        }
        cout<<q * r - y<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,x,y,p,q;
ll search(ll l,ll r)
{
ll mid=(l+r)>>1;
if (l==r) return l;
if (r-l==1) return mid*q<y||mid*p<x||mid*q-y<mid*p-x?r:l;
return mid*q<y||mid*p<x||mid*q-y<mid*p-x?search(mid,r):search(l,mid);
}
int main()
{
for (scanf("%lld",&t);t--;)
  {
  scanf("%lld%lld%lld%lld",&x,&y,&p,&q);
  if (p>q) {puts("-1");continue;}
  if ((double)x/y==(double)p/q) {puts("0");continue;}
  if (p==q&&x<y||p==0&&x>0) {puts("-1");continue;}
  printf("%lld\n",search(1,1e9)*q-y);
  }
}


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

using namespace std;
const long long maxn = 1e10 + 1;

int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		long long x, y, p, q;
		scanf("%I64d%I64d%I64d%I64d", &x, &y, &p, &q);

		long long l = 0, r = maxn, mid = 0, ans = -1;
		while (l < r - 1) {
			mid = (l + r) / 2;
			if (mid * p >= x && (mid * q - y >= mid * p - x)) {
				// so, we can choose a smaller k
				ans = mid;
				r = mid;
			} else l = mid;
		}
		if (ans == -1) printf("-1\n");
		else cout << ans * q - y << endl;
	}
	return 0;
}


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

using namespace std;
const int maxn = 1e3 + 1;

int main () {
	int t;
	scanf("%d", &t);
	for (int i = 1; i <= t; i++) {
		int x, y, p, q;
		scanf("%d %d %d %d", &x, &y, &p ,&q);
		if (x == p && y == q) printf("0\n");
		else {
			int l = 0, r = 1e9 + 1;
			while (l < r - 1) {
				int mid = (l + r) / 2;
				int k = mid / p;
				if (k * p >= x && (k * q - y >= k * p - x)) r = mid;
				else l = mid;
			}
			if (r == 1e9 + 1) printf("-1\n");
			else {
				int ans = r / p;
				printf("%d\n", ans * q - y);
			}
		}
	}
	return 0;
}


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

using namespace std;
const int maxn = 1e3 + 1;

int main () {
	int t;
	scanf("%d", &t);
	for (int i = 1; i <= t; i++) {
		int x, y, p, q;
		scanf("%d %d %d %d", &x, &y, &p ,&q);
		if (x == p && y == q) printf("0\n");
		else {
			int l = 0, r = 1e9 + 1;
			while (l < r - 1) {
				int mid = (l + r) / 2;
				int k = mid / q;
				if (k * p >= x && (k * q - y >= k * p - x)) r = mid;
				else l = mid;
			}
			if (r == 1e9 + 1) printf("-1\n");
			else {
				int ans = r / q;
				printf("%d\n", ans * q - y);
			}
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <math.h>
// Shortcuts for "common" data types in contests
typedef long long ll;
//typedef vector<int> vi;
//typedef pair<int, int> ii;
//typedef vector<ii> vii;
//typedef set<int> si;
//typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define REPs(i, a, b, s) \
for (int i = int(a); i <= int(b); i+= s)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    REP(j,0,n-1){
        if(j%2 == 0){
            REP(i,0, m-1) cout << "#";
            cout << endl;
        } else {
            if(j%4 == 3) cout << "#";
            else cout << ".";
            REP(i, 1, m-2) cout << ".";
            if(j%4 == 1) cout << "#";
            else cout << ".";
            cout << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define in cin>>
#define out cout<<
#define M 1002
#define FOR(i,k,l)   for(int i(k); i<l; i++)
#define Si set<int>
#define Mii map<int,int>
#define Mss map<string,string>
#define vi vector<int>

using namespace std;

int main(){
ios_base::sync_with_stdio(false);
int n,m;

    in(n);in(m);
    int cp=1;
    FOR(i,0,n){
        FOR(j,0,m){
           if(i==0 || i== n-1  || i%2==0){
                out("#");
           }
           else if(cp == 1){
               // out(j);//out(endl);
                if(j== m-1){
                    cp=0;
                    out("#");
                }
                else
                    out(".");

           }
           else if(cp == 0){
                if(j==0)
                    out("#");
                else{
                    out(".");
                    if(j== m-1)
                        cp=1;
                }
           }
        }
        out(endl);

    }

return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <array>
#include <forward_list>
#include <unordered_set>
//#include <vld.h>
using namespace std;

#ifndef LOCAL
//#define LOCAL
#endif

#define INF 1000000000
#define eps 1.0e-11
const int NO_VALUE = -1;
typedef pair<int, int> ii;
typedef long long ll;
const double PI = atan(1.0)*4;

int R, C;

void print(int line = 1, int ri = 3, int le = 1) {
    if (line % 2 != 0) {
        cout << string(C, '#') << "\n";
        if (line == R) {
            return;
        }
        print(line + 1, ri + 1, le + 1);
    }
    else {
        if (le == 4) {
            cout << "#" + string(C - 1, ' ') + "\n";
            print(line + 1, ri + 1, 1);
        }
        else if (ri == 4) {
            cout << string(C - 1, ' ') + "#\n";
            print(line + 1, 1, le + 1);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("C:\\input.txt", "r", stdin);
    //freopen("C:\\output.txt", "w+", stdout);
#endif
    cin >> R >> C;
    print();

    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <array>
#include <forward_list>
#include <unordered_set>
//#include <vld.h>
using namespace std;

#ifndef LOCAL
//#define LOCAL
#endif

#define INF 1000000000
#define eps 1.0e-11
const int NO_VALUE = -1;
typedef pair<int, int> ii;
typedef long long ll;
const double PI = atan(1.0)*4;

int R, C;

void print(int line = 1, int ri = 3, int le = 1) {
    if (line % 2 != 0) {
        cout << string(C, '#') << "\n";
        if (line == R) {
            return;
        }
        print(line + 1, ri + 1, le + 1);
    }
    else {
        if (le == 4) {
            cout << "#" + string(C - 1, '.') + "\n";
            print(line + 1, ri + 1, 1);
        }
        else if (ri == 4) {
            cout << string(C - 1, '.') + "#\n";
            print(line + 1, 1, le + 1);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("C:\\input.txt", "r", stdin);
    //freopen("C:\\output.txt", "w+", stdout);
#endif
    cin >> R >> C;
    print();

    return 0;
}


// :)

#include <bits/stdc++.h>

#define llong long long

#define pb push_back
#define mp make_pair

#define F first
#define S second

using namespace std;

const int INF = (int) 1e9 + 7;
const int MXN = (int) 1e3 + 7;

const double EPS = 1e-9;

int n, m;
char a[MXN][MXN];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        int c = m;
        if (i & 1) {
            while (c--)
                putchar('#');
        }
        else {
            int h = 1 + i / 2;
            if (h & 1) putchar('#');
            while (--c) putchar('.');
            if (!(h & 1)) putchar('#');
        }
        puts("");
    }

    return 0;
}


// :)

#include <bits/stdc++.h>

#define llong long long

#define pb push_back
#define mp make_pair

#define F first
#define S second

using namespace std;

const int INF = (int) 1e9 + 7;
const int MXN = (int) 1e3 + 7;

const double EPS = 1e-9;

int n, m;
char a[MXN][MXN];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        int c = m - 1;
        while (c--) putchar(i & 1 ? '#' : '.');
        puts("#");
    }

    return 0;
}


#include<iostream>
#include<string>
#define rep(i,j,k) for(i=j;i<=k;i++)
using namespace std;
int i,j,k;
char str[60][60];
int main()
{
    int n, m;
    cin >> n >> m;
    char str[n][m];
     rep(i,1,n)
    rep(j,1,m)
        if (i%2==1)
            str[i][j]='#';
        else
            str[i][j]='.';
    rep(i,1,n)
    {
        if(i%2==0)
          {
            if(i%4==2)
              str[i][m]='#';
            else
              str[i][1]='#';
          }
    }
    for (int i = 1; i <= n;i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cout << str[i][j];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#define rep(i,j,k) for(i=j;i<=k;i++)
using namespace std;
int i,j,k;
char str[60][60];
int main()
{
    int n, m;
    cin >> n >> m;
     rep(i,1,n)
    rep(j,1,m)
        if (i%2==1)
            str[i][j]='#';
        else
            str[i][j]='.';
    rep(i,1,n)
    {
        if(i%2==0)
          {
            if(i%4==2)
              str[i][m]='#';
            else
              str[i][1]='#';
          }
    }
    for (int i = 1; i <= n;i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cout << str[i][j];
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

int main(){
long long int n,m;
char a[50][50];
cin>>n>>m;
for (int j=0;j<n;j+=2)
for (int i=0;i<m;i++){
a[j][i]='#';
}
for (int j=1;j<n;j+=4){
for (int i=0;i<m-1;i++){
a[j][i]='.' ;
a[j][n-1]='#';}}

for (int j=3;j<n;j+=4){
for (int i=1;i<m;i++){
a[j][i]='.';
a[j][0]='#';}}

for(int i=0;i<n;i++){
for (int j=0;j<m;j++){
cout<<a[i][j];}cout<<endl;}}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

int main(){
long long int n,m;
char a[50][50];
cin>>n>>m;
for (int j=0;j<n;j+=2)
for (int i=0;i<m;i++){
a[j][i]='#';
}
for (int j=1;j<n;j+=4){
for (int i=0;i<m-1;i++){
a[j][i]='.' ;
a[j][m-1]='#';}}

for (int j=3;j<n;j+=4){
for (int i=1;i<m;i++){
a[j][i]='.';
a[j][0]='#';}}

for(int i=0;i<n;i++){
for (int j=0;j<m;j++){
cout<<a[i][j];}cout<<endl;}}


#include<iostream>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%4==2){
            for(int j=1;j<m;j++)
                cout<<'.';
            cout<<'#'<<endl;
        }
        else if(i%4==0){
            cout<<'#';
            for(int j=1;j<m;j++)
                cout<<'.';
            cout<<endl;
        }
        else{
            for(int j=1;j<=m;j++)
                cout<<'#';
            cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%4==2){
            for(int j=1;j<m;j++)
                cout<<'.';
            cout<<'#'<<endl;
        }
        else if(i%4==0){
            cout<<'#'<<endl;
            for(int j=1;j<m;j++)
                cout<<'.';

        }
        else{
            for(int j=1;j<=m;j++)
                cout<<'#';
            cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        if(i%2==0){
            for(int j=1;j<m;j++)
                cout<<'.';
            cout<<'#'<<endl;
        }
        else{
            for(int j=1;j<=m;j++)
                cout<<'#';
            cout<<endl;
        }
    }
    return 0;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    vector<string> S(n);
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(i%2==0) S[i]+='#'; else S[i]+='.';
    bool x=1;
    for(int i=1;i<n;i+=2) if(x){x=0;S[i][m-1]='#';} else{x=0;S[i][0]='#';}
    for(int i=0;i<n;i++) cout<<S[i]<<endl;
    return 0;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    vector<string> S(n);
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(i%2==0) S[i]+='#'; else S[i]+='.';
    bool x=1;
    for(int i=1;i<n;i+=2) if(x){x=0;S[m-1]='#';} else{x=0;S[0]='#';}
    for(int i=0;i<n;i++) cout<<S[i]<<endl;
    return 0;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    vector<string> S(n);
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(i%2==0) S[i]+='#'; else S[i]+='.';
    bool x=1;
    for(int i=1;i<n;i+=2) if(x){x=0;S[i][m-1]='#';} else{x=1;S[i][0]='#';}
    for(int i=0;i<n;i++) cout<<S[i]<<endl;
    return 0;
}


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

int main() {
    short n, m;
    scanf("%hi%hi",&n, &m);
    for(auto j = 1; j <= n; j++)
        for(auto i = 1; i <= m; i++) {
            if(j % 2)
                putchar('#');
            else
                if(i == 1 && (j % 4 == 0))
                    putchar('#');
                else
                    if(i == m && (j % 4 == 2))
                        putchar('#');
                    else
                        putchar('.');
            if(i == m)
                putchar('\n');
        }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    short n, m;
    cin >> n >> m;
    for(short j = 1; j <= n; j++)
        for(short i = 1; i <= m; i++) {
            if(j % 2)
                cout << '#';
            else
                if(i == 1 && (j % 4 == 0))
                    cout << '#';
                else
                    if(i == m && (j % 4 == 2))
                        cout << '#';
                    else
                        cout << '.';
            if(i == m)
                cout << endl;
        }
    return 0;
}


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

int main() {
    short n, m;
    scanf("%ih%ih",&n, &m);
    for(auto j = 1; j <= n; j++)
        for(auto i = 1; i <= m; i++) {
            if(j % 2)
                putchar('#');
            else
                if(i == 1 && (j % 4 == 0))
                    putchar('#');
                else
                    if(i == m && (j % 4 == 2))
                        putchar('#');
                    else
                        putchar('.');
            if(i == m)
                putchar('\n');
        }
    return 0;
}


#include <iostream>
using namespace std ;

int main(){

int n,m ;
cin >> n >> m ;
char arr[n][m] ;

for (int i =1;i<=n ;i+=2
){
    for(int j=1; j<=m ; j++){arr[i][j]= '#' ;}
}
for(int i=2 ; i<=n ; i+=4){
    arr[i][n]= '#' ;
    for(int j = 1 ;j<m ;j++){arr[i][j]= '.' ;}
}
for (int i=4 ; i <= n ; i +=4 )
{
    arr[i][1]='#' ;
    for(int j=2 ; j<=m ; j++){arr[i][j]= '.' ;}
}
for (int i =1 ;i<=n ; i++){

    for (int j = 1 ;j<=m ;j++){

        cout << arr[i][j] ;
    }cout <<endl ;
}

}


#include <iostream>
using namespace std ;

int main(){

int n,m ;
cin >> n >> m ;
char arr[n][m] ;

for (int i =0;i<n ;i+=2
){
    for(int j=0; j<m ; j++){arr[i][j]= '#' ;}
}
for(int i=1 ; i<n ; i+=4){

    for(int j = 0 ;j<m ;j++){arr[i][j]= '.' ;}
    arr[i][m-1]= '#' ;
}
for (int i=3 ; i < n ; i +=4 )
{

    for(int j=1 ; j<m ; j++){arr[i][j]= '.' ;}
    arr[i][0]='#' ;
}
for (int i =0 ;i<n ; i++){

    for (int j = 0 ;j<m ;j++){

        cout << arr[i][j] ;
    }cout <<endl ;
}

}


#include <iostream>
using namespace std;

int main()
{
    int x,y;
    bool check=false;
    cin>>x>>y;
    char arr[50][50];
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            if(i%2==0)
            {
                arr[i][j]='#';
            }
            else if(i%2!=0&&check==false)
            {
                if(j==y-1)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
                check=true;
            }
            else if(i%2!=0&&check==true)
            {
                if(j==0)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
                check=false;
            }
        }
    }
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            cout<<arr[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int x,y;
    bool check=false;
    cin>>x>>y;
    char arr[50][50];
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            if(i%2==0)
            {
                arr[i][j]='#';
            }
            else if(i%2!=0&&check==false)
            {
                if(j==y-1)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
            }
            else if(i%2!=0&&check==true)
            {
                if(j==0)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
            }
        }

      if(i%2!=0) {        if(check==true){check=false;}
        else {check=true;}
      }
    }
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            cout<<arr[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int x,y;
    bool check=false;
    cin>>x>>y;
    char arr[50][50];
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            if(i%2==0)
            {
                arr[i][j]='#';
            }
            else if(i%2!=0&&check==false)
            {
                if(j==y-1)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
            }
            else if(i%2!=0&&check==true)
            {
                if(j==0)
                {
                    arr[i][j]='#';
                }
                else
                {
                    arr[i][j]='.';
                }
            }
        }

      if(i%2!=0) {cout<<"hasona"<<endl;
        if(check==true){check=false;}
        else {check=true;}
      }
    }
    for(int i=0 ; i<x ; i++)
    {
        for(int j=0 ; j<y ; j++)
        {
            cout<<arr[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> VS;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
template<class T> bool iseven(T n) {if ( (n & 1) == 0 ) return 1; return false; }
int readInt() { int n; if ( scanf("%d", &n) != 1 ) throw("invalid input"); return n; }

int main(){
    int n = readInt(), m = readInt(), x = 0;
    bool first = true;
    VS matrix(n, string(m, '.'));
    FOR(x, 0, n){
        if(iseven(x)){
            matrix[x] = string(m, '#');
        } else {
            if(first) matrix[x][m-1] = '#';
            else matrix[x][0] = '#';
            first = !first;
        }
        cout << matrix[x] << endl;
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> VS;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
template<class T> bool iseven(T n) {if ( (n & 1) == 0 ) return 1; return false; }
int readInt() { int n; if ( scanf("%d", &n) != 1 ) throw("invalid input"); return n; }

int main(){
    int n = readInt(), m = readInt(), x = 0;
    bool first = true;
    VS matrix(n, string(m, '.'));
    FOR(x, 0, n){
        if(iseven(x)){
            matrix[x] = string(m, '#');
        } else {
            if(first) matrix[x][m-1] = '#';
            else matrix[x][0] = '#';
            first = !first;
        }
        cout << matrix[x] << endl;
    }
    return 0;
}


#include<iostream>d;
using namespace std ;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		if(i%2!=0){
			for(int i=1;i<=m;i++){
				cout<<"#";
			}
			cout<<endl;
		}
		else{
			if(i%4==2){
				for(int i=1;i<m;i++){
					cout<<".";
				}
				cout<<"#"<<endl;
			}
			if(i%4==0){
				cout<<"#";
				for(int i=1;i<m;i++){
					cout<<".";
				}
				cout<<endl;
			}
		}
	}
}


#include<iostream>
using namespace std ;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		if(i%2!=0){
			for(int i=1;i<=m;i++){
				cout<<"#";
			}
			cout<<endl;
		}
		else{
			if(i%4==2){
				for(int i=1;i<m;i++){
					cout<<".";
				}
				cout<<"#"<<endl;
			}
			if(i%4==0){
				cout<<"#";
				for(int i=1;i<m;i++){
					cout<<".";
				}
				cout<<endl;
			}
		}
	}
}


#include <iostream>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int r = 1;

    while(r <= n)
    {
        if(r % 2 == 1)
        {
            for(int i = 0; i < m; i++)
                cout << "#";
            cout << endl;
        }
        else
        {
            for(int j = 0; j < m - 1; j++)
                cout << ".";
            cout << "#" << endl;
        }
        r++;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int r = 1;
    bool l = false;

    while(r <= n)
    {
        if(r % 2 == 1)
        {
            for(int i = 0; i < m; i++)
                cout << "#";
            cout << endl;
        }
        else if(r % 2 == 0 && l == false)
        {
            for(int j = 0; j < m - 1; j++)
                cout << ".";
            cout << "#" << endl;
            l = true;
        }
        else
        {
            cout << "#";
            for(int j = 0; j < m - 1; j++)
                cout << ".";
            cout << endl;
            l = false;
        }
        r++;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    char ans[55][55];
    int n, m;
    cin >> n >> m;
    bool first = false;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            if (i & 1 != 0)
                ans[i][j] = '#';
            else if (i%4==0)
            {
                if (j == 1)
                    ans[i][j] = '#';
                else
                    ans[i][j] = '.';
            }
            else
            {
                if (j == m)
                    ans[i][j] = '#';
                else
                    ans[i][j] = '.';
            }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cout << ans[i][j];
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	char ans[55][55];
	int n, m;
	cin >> n >> m;
	bool first = false;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			if (i & 1 != 0)
				ans[i][j] = '#';
			else if (first)
			{
				if (j == 1)
					ans[i][j] = '#';
				else
					ans[i][j] = '.';
				first = false;
			}
			else
			{
				if (j == m)
					ans[i][j] = '#';
				else
					ans[i][j] = '.';
				first = true;
			}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			cout << ans[i][j];
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldb;
typedef unsigned uint;

#define mp make_pair
#define pb push_back
#define sqr(o) ((o)*(o))

using namespace std;

#define name "file"

int n, m, ch;
string ans;

int main () {
/*#ifdef LOCAL
	freopen (name".in", "r", stdin);
	freopen (name".out", "w", stdout);
#endif  */

	cin >> n >> m;

	for(int i = 0; i < n; i++) {
		string add;

		if (i & 1) {
			add = string (m, '.');
			if (ch)
				add[0] = '#';
			else
				add.back () = '#';

			ch ^= 1;
		}

		else
			add = string (m, '#');

		add += '\n';
		ans += add;
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldb;
typedef unsigned uint;

#define mp make_pair
#define pb push_back
#define sqr(o) ((o)*(o))

using namespace std;

#define name "file"

int n, m, ch;
string ans;

int main () {
/*#ifdef LOCAL
	freopen (name".in", "r", stdin);
	freopen (name".out", "w", stdout);
#endif  */

	cin >> n >> m;

	for(int i = 0; i < n; i++) {
		string add;

		if (i & 1) {
			add = string (m, '.');
			if (ch)
				add[0] = '*';
			else
				add.back () = '*';

			ch ^= 1;
		}

		else
			add = string (m, '*');

		add += '\n';
		ans += add;
	}

	cout << ans;

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
   int a,b,c=1;
   cin>>a>>b;
   for (int i=1;i<=a;i++){
    for (int j=1;j<=b;j++){
        if (i%2!=0){
            cout<<"#";
        }
        else {
            if (c%2!=0){
                if (j==b){
                    cout<<"#";
                }
                else {
                cout<<".";
                }
            }
            else if (c%2==0){
                if (j==1){
                    cout<<"#";
                }
                else {
                    cout<<".";
                }
            }
            c++;
        }
    }
    cout<<endl;
   }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
   int a,b,c=0;
   cin>>a>>b;
   for (int i=1;i<=a;i++){
    for (int j=1;j<=b;j++){
        if (i%2!=0){
            cout<<"#";
        }
        else if (i%2==0) {
            if (c%2!=0){
                if (j==b){
                    cout<<"#";
                }
                else {
                cout<<".";
                }
            }
            else if (c%2==0){
                if (j==1){
                    cout<<"#";
                }
                else {
                    cout<<".";
                }
            }
        }
    }
    if (i%2!=0){
    c++;
    }
    cout<<endl;
   }
    return 0;
}


#include <bits/stdc++.h>

#define maxn 1000
#define fi first
#define se second

using namespace std;

int n,m;

char ar[maxn][maxn];

int main()
{
	int t=0;

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

	for(int i=1;i<=n;i++)
	{
		if(i%2)
			for(int j=0;j<m;j++)
				ar[i][j]='#';

		else
		{
			if(t)
			{
				ar[i][0]='#';

				for(int j=1;j<m;j++)
					ar[i][j]='.';

				t=0;
			}

			else
			{
				t=1;

				ar[i][m-1]='#';

				for(int j=0;j<m-1;j++)
					ar[i][j]='.';
			}
		}
	}

	for(int i=1;i<=n;i++)
		printf("%s\n",ar[i]);

	return 0;
}


#include <bits/stdc++.h>

#define maxn 1000
#define fi first
#define se second

using namespace std;

int n,m;
char ar[maxn][maxn];

int main()
{
	int t=0;

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

	memset(ar,'.',sizeof ar);

	for(int i=1;i<=n;i++)
	{
		if((i%2))
		{
			memset(ar[i] , '*' , sizeof ar[i]);
		}

		else
		{
			if(!t)
			{
				ar[i][m]='*';
				t=1;
			}

			else
			{
				ar[i][1]='*';
				t=0;
			}
		}
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%c",ar[i][j]);

		printf("\n");
	}

	return 0;
}


#include<iostream>
using namespace std;
void all_hash(int m)
{
        for(int i=0;i<m;i++)
                cout<<"#";
        cout<<"\n";
}
void left_hash(int m)
{
        cout<<"#";
        for(int i=0;i<m-1;i++)
                cout<<".";
        cout<<"\n";
}
void right_hash(int m)
{
        for(int i=0;i<m-1;i++)
                cout<<".";
        cout<<"#";
        cout<<"\n";
}
int main()
{
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
                if(i%2==0)
                        all_hash(m);
                else if(i%3==1)
                        right_hash(m);
                else
                        left_hash(m);
        }
        return 0;
}


#include<iostream>
using namespace std;
void all_hash(int m)
{
        for(int i=0;i<m;i++)
                cout<<"#";
        cout<<"\n";
}
void left_hash(int m)
{
        cout<<"#";
        for(int i=0;i<m-1;i++)
                cout<<".";
        cout<<"\n";
}
void right_hash(int m)
{
        for(int i=0;i<m-1;i++)
                cout<<".";
        cout<<"#";
        cout<<"\n";
}
int main()
{
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
                if(i%2==0)
                        all_hash(m);
                else if(i%4==1)
                        right_hash(m);
                else
                        left_hash(m);
        }
        return 0;
}


//codeforces round 290 Div2 A
#include <iostream>
using namespace std;

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        char arr[55][55];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                arr[i][j] = '.';
            }
        }
        int i = 0, j = 0;
        while (i < n && j < m)
        {
            for (j = 0; j < m; j++)
            {
                arr[i][j] = '#';
            }
            if (i + 1 < n)
                arr[i + 1][j-1] = '#';
            i += 2;
            for (j = m - 1;j >= 0; --j)
            {
                arr[i][j] = '#';
            }
            if (i + 1 < n)
                arr[i + 1][j+1] = '#';
            i += 2;
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cout << arr[i][j];
            }
            cout << endl;
        }
    }
}


//codeforces round 290 Div2 A
#include <iostream>
using namespace std;

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        char arr[55][55];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (i % 2 == 0)
                    arr[i][j] = '#';
                else
                {
                    int a = i / 2;
                    if (j == m - 1 && a % 2 == 0)
                        arr[i][j] = '#';
                    else if (j == 0 && a % 2 == 1)
                        arr[i][j] = '#';
                    else
                        arr[i][j] = '.';
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cout << arr[i][j];
            }
            cout << endl;
        }
    }
}


#include <iostream>
using namespace std;

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        char arr[55][55];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                int a = i / 2;
                if (i % 2 == 0)
                    arr[i][j] = '#';
                else
                {
                    if (j == m - 1 && a == 0)
                        arr[i][j] = '#';
                    else if (j == 0 && a == 1)
                        arr[i][j] = '#';
                    else
                        arr[i][j] = '.';
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cout << arr[i][j];
            }
            cout << endl;
        }
    }
}


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

#define pi 2*acos(0.0)
#define all(v) v.begin(),v.end()
#define coff ios_base::sync_with_stdio(0);

#define ff first
#define se second
#define pb push_back
#define sz(a) ((int)a.size())
#define ST(v) sort(all(v))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define cover(a,d) memset(a,d,sizeof(a))
#define popcount(i) __builtin_popcount(i)      //count one. in long long use __builtin_popcountll(i)
#define parity(i)   __builtin_parity(i)       //evenparity 0 and odd parity 1
#define btz(a)   __builtin_ctz(a)            //count binary trailling zero
#define un(v) ST(v), (v).erase(unique(all(v)),v.end())
#define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

typedef  long long ll;
typedef  unsigned long long ull;

template <typename T>string toString( T Number ){stringstream st;st << Number;return st.str();}
int stringconvert(string s){int p; istringstream st(s); st>>p ; return p;}

//upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())

//Debug
#define dbg(x) cout<<#x<<'='<<x<<endl;
#define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl;
#define nl puts("")

//File input/output
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)

ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; }
ll modInverse(ll a, ll m){return bigmod(a,m-2,m);}

////============ CONSTANT ===============////
#define inf   1<<30                                           //infinity value
#define eps   1e-9
#define mx    300010
#define mod   1000000007
////=====================================////
int main()
{
    int n,m ;
    scanf("%d %d",&n,&m);

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i%2==0)
            {
                printf("#");
            }
            else
            {
                if(j==0 && ((i+1)/2)%2==0)
                {
                    printf("#");
                }
                else if(j==m-1 && ((i+1)/2)%2==1)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
        }
        puts("");
    }

    return 0;
}


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

#define pi 2*acos(0.0)
#define all(v) v.begin(),v.end()
#define coff ios_base::sync_with_stdio(0);

#define ff first
#define se second
#define pb push_back
#define sz(a) ((int)a.size())
#define ST(v) sort(all(v))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define cover(a,d) memset(a,d,sizeof(a))
#define popcount(i) __builtin_popcount(i)      //count one. in long long use __builtin_popcountll(i)
#define parity(i)   __builtin_parity(i)       //evenparity 0 and odd parity 1
#define btz(a)   __builtin_ctz(a)            //count binary trailling zero
#define un(v) ST(v), (v).erase(unique(all(v)),v.end())
#define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

typedef  long long ll;
typedef  unsigned long long ull;

template <typename T>string toString( T Number ){stringstream st;st << Number;return st.str();}
int stringconvert(string s){int p; istringstream st(s); st>>p ; return p;}

//upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())

//Debug
#define dbg(x) cout<<#x<<'='<<x<<endl;
#define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl;
#define nl puts("")

//File input/output
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)

ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; }
ll modInverse(ll a, ll m){return bigmod(a,m-2,m);}

////============ CONSTANT ===============////
#define inf   1<<30                                           //infinity value
#define eps   1e-9
#define mx    300010
#define mod   1000000007
////=====================================////
int main()
{
    int n,m ;
    scanf("%d %d",&n,&m);

    int f=1;
    string s[110];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i%2==0)
            {
                s[i][j]='#';
            }
            else
            {
                s[i][j]='.';
            }
        }
        if(i%2==1)
        {
            if(f)
            {
                s[i][m-1]='#';
                f=0;
            }
            else
            {
                s[i][0]='#';
                f=1;
            }

        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            printf("%c",s[i][j]);
        }
        puts("");
    }

    return 0;
}


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

#define pi 2*acos(0.0)
#define all(v) v.begin(),v.end()
#define coff ios_base::sync_with_stdio(0);

#define ff first
#define se second
#define pb push_back
#define sz(a) ((int)a.size())
#define ST(v) sort(all(v))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define cover(a,d) memset(a,d,sizeof(a))
#define popcount(i) __builtin_popcount(i)      //count one. in long long use __builtin_popcountll(i)
#define parity(i)   __builtin_parity(i)       //evenparity 0 and odd parity 1
#define btz(a)   __builtin_ctz(a)            //count binary trailling zero
#define un(v) ST(v), (v).erase(unique(all(v)),v.end())
#define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

typedef  long long ll;
typedef  unsigned long long ull;

template <typename T>string toString( T Number ){stringstream st;st << Number;return st.str();}
int stringconvert(string s){int p; istringstream st(s); st>>p ; return p;}

//upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())

//Debug
#define dbg(x) cout<<#x<<'='<<x<<endl;
#define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl;
#define nl puts("")

//File input/output
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)

ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; }
ll modInverse(ll a, ll m){return bigmod(a,m-2,m);}

////============ CONSTANT ===============////
#define inf   1<<30                                           //infinity value
#define eps   1e-9
#define mx    300010
#define mod   1000000007
////=====================================////
int main()
{
    coff;
    int n,m;
    cin>>n>>m;

    string s[110];
    int f=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i&1)
            {
                s[i][j]='#';
            }
            else
            {
                s[i][j]='.';
            }
        }
        if(i%2==0)
        {
            if(f)
            {
                s[i][m]='#';
                f=0;
            }
            else
            {
                s[i][1]='#';
                f=1;
            }
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<s[i][j];
        }
        cout<<"\n";
    }

    return 0;
}


#include <iostream>

using namespace std;

inline
void use_io_optimizations()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    use_io_optimizations();

    int n, m;
    cin >> n >> m;
    bool f = false;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            for (int j = 0; j < m; ++j) {
                cout << '#';
            }
            cout << '\n';
        }
        else {
            if (!f) {
                for (int j = 0; j < m - 1; ++j) {
                    cout << '.';
                }
                cout << '#' << '\n';
                f = !f;
            }
            else {
                cout << '#';
                for (int j = 0; j < m - 1; ++j) {
                    cout << '.';
                }
                cout << '\n';
                f = !f;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

inline
void use_io_optimizations()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    use_io_optimizations();

    unsigned int rows;
    unsigned int columns;

    cin >> rows >> columns;

    string row_a(columns, '#');
    string row_b {string(columns - 1, '.') + '#'};
    string row_c {'#' + string(columns - 1, '.')};

    for (unsigned int i {0}; i < rows; ++i)
    {
        if (i % 2 == 0)
        {
            cout << row_a << '\n';
        }
        else if (i % 4 == 1)
        {
            cout << row_b << '\n';
        }
        else
        {
            cout << row_c << '\n';
        }
    }

    return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,m,i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		if(i%2==1)
			{
				for(j=1;j<=m;j++)
					{cout<<"#";}
					cout<<endl;
			}
		else
		{
			for(j=1;j<=m;j++)
				{if(i%4==2)
				{
					if(j==1)
						cout<<"#";
					else
						cout<<".";
				}
				else
					{if(j==m)
						cout<<"#";
					else
						cout<<".";}
				}
				cout<<endl;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,m,i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		if(i%2==1)
			{
				for(j=1;j<=m;j++)
					{cout<<"#";}
					cout<<endl;
			}
		else
		{
			for(j=1;j<=m;j++)
				{if(i%4!=2)
				{
					if(j==1)
						cout<<"#";
					else
						cout<<".";
				}
				else
					{if(j==m)
						cout<<"#";
					else
						cout<<".";}
				}
				cout<<endl;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,m;
    bool flag = true;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i%2 == 0)
            {
                cout<<"#";
            }
            else
            {
                if(flag)
                {
                    if(j == m-1)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
                else
                {
                    if(j == 0)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
            }
        }
        if(i%2 != 0) flag = !flag;
        cout<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,m;
    bool flag = true;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i%2 == 0)
            {
                cout<<"#";
            }
            else
            {
                if(flag)
                {
                    if(j == m-1)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
                else
                {
                    if(j == 0)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
                flag = !flag;
            }
        }
        cout<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,m;
    bool flag = true;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i%2 == 0)
            {
                cout<<"#";
            }
            else
            {
                if(flag)
                {
                    if(j == m-1)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
                else
                {
                    if(j == 0)
                    {
                        cout<<"#";
                    }
                    else
                    {
                        cout<<".";
                    }
                }
            }
        }
        if(i%2 != 0) flag != flag;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i){
		if (i % 2 == 0) {
			if (i % 4 == 0)
				cout << '#';
			for (int j = 1; j < m; ++j)
				cout << '.';
			if (i % 4 == 2)
				cout << '#';
		}
		else {
			for (int j = 1; j <= m; ++j)
				cout << '#';
		}
		cout << '\n';
	}
	system("pause");
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i){
		if (i % 2 == 0) {
			if (i % 4 == 0)
				cout << '#';
			for (int j = 1; j < m; ++j)
				cout << '.';
			if (i % 4 == 2)
				cout << '#';
		}
		else {
			for (int j = 1; j <= m; ++j)
				cout << '#';
		}
		cout << '\n';
	}
	//system("pause");
	return 0;
}


//Author: Krishna Kishore
//Work Smart Not Hard
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<sstream>
#include<bitset>
#include<algorithm>
#include<utility>
#include<numeric>
using namespace std;

//Input Macros

//Useful Constants
#define INF                         (int)1e9        //1000000000=10^9
#define EPS                         1e-9        //10^-9

//I Hate Using Macros For Loops

int main()
{
   std::ios_base::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if( (i%2) || (i%4==2 && j==m) || (i%4==0 && j==1)) printf("#");
            else printf(".");
        }
        printf("\n");
        //cout<<endl;
    }
    return 0;
}


//Author: Krishna Kishore
//Work Smart Not Hard
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<sstream>
#include<bitset>
#include<algorithm>
#include<utility>
#include<numeric>
using namespace std;

//Input Macros

//Useful Constants
#define INF                         (int)1e9        //1000000000=10^9
#define EPS                         1e-9        //10^-9

//I Hate Using Macros For Loops

int main()
{
   std::ios_base::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if( (i%2) || (i%4==2 && j==m) || (i%4==0 && j==1)) printf("#");
            else printf(".");
        }
        //printf("\n");
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep1 for(int i=1; i<=n; i++)
#define rep2 for(int j=1; j<=m; j++)

using namespace std;

char a[50][50];
int n, m;

int main(){
		cin >> n >> m;
	rep1{
		rep2{
	  		if(i%2==1){
	  			a[i][j]='#';
	  	  	}else{
	  	  		a[i][j]='.';
	  	  	}
	  	}
   	}
   	rep1{
   		rep2{
			if(i%2==0){
				if(i%4==0)
					a[i][1]='#';
			   	else
			   		a[i][m]='#';
		  	}
   	   	}
   	}
   	rep1{
   		rep2{
   			cout << a[i][j];
   	   	}
   	   	cout << endl;
  	}
   	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep1 for(int i=1; i<=n; i++)
#define rep2 for(int j=1; j<=m; j++)

using namespace std;

char a[50][50];
int n, m;

int main(){
		cin >> n >> m;
	rep1{
		rep2{
	  		if(i%2==1){
	  			a[i][j]='#';
	  	  	}else{
	  	  		a[i][j]='.';
	  	  	}
	  	}
   	}
   	rep1{
   		rep2{
			if(i%2==0){
				if(i%4==2)
					a[i][m]='#';
			   	else
			   		a[i][1]='#';
		  	}
   	   	}
   	}
   	rep1{
   		rep2{
   			cout << a[i][j];
   	   	}
   	   	cout << endl;
  	}
   	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		char str[n + 5][m + 5];
		for (int i = 0; i != n; ++i)
		{
			if (i % 2)
			{
				if (i / 2 % 2) str[i][m - 1] = '.';
				else str[i][0] = '.';
				for (int j = 1; j != m - 1; ++j)
					str[i][j] = '.';
			}
		}
		for (int i = 0; i != n; ++i)
			for (int j = 0; j != m; ++j)
			{
				if (str[i][j] != '.') str[i][j] = '#';
				cout << str[i][j] << " \n"[j == m - 1];
			}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		char str[n + 5][m + 5];
		for (int i = 0; i != n; ++i)
		{
			if (i % 2)
			{
				if (i / 2 % 2) str[i][m - 1] = '.';
				else str[i][0] = '.';
				for (int j = 1; j != m - 1; ++j)
					str[i][j] = '.';
			}
		}
		for (int i = 0; i != n; ++i)
		{
			for (int j = 0; j != m; ++j)
			{
				if (str[i][j] != '.') str[i][j] = '#';
				cout << str[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}


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

int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		char str[n + 5][m + 5];
		memset(str, '#', sizeof(str));
		for (int i = 0; i != n; ++i)
		{
			if (i % 2)
			{
				if (i / 2 % 2) str[i][m - 1] = '.';
				else str[i][0] = '.';
				for (int j = 1; j != m - 1; ++j)
					str[i][j] = '.';
			}
			for (int j = 0; j != m; ++j)
				cout << str[i][j];
			cout << endl;
		}
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char board[n][m];
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            if(i%2 == 0)
                board[i][j] = '#';
            else
                board[i][j] = '.';
        }
    int temp = m-1;
    for(int i=1; i<n; i=i+2)
    {
        board[i][temp] = '#';
        if(temp == 0)
            temp = m-1;
        else
            temp = 0;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++)
        {
            cout<<board[i][j];
        }
        cout<<endl;
    }
}


#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char board[n][m];
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            if(i%2 == 0)
                board[i][j] = '#';
            else
                board[i][j] = '.';
        }
    int temp = 0;
    for(int i=1; i<n; i=i+2)
    {
        board[i][temp] = '#';
        if(temp == 0)
            temp = m-1;
        else
            temp = 0;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++)
        {
            cout<<board[i][j];
        }
        cout<<endl;
    }
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
#include <List>
#include <cmath>
#include <algorithm>
#define MaxSize
#define LL long long

using namespace std;

int main()
{
    int n,m;
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
        for(i = 1; i <= n; ++i)
        {
            if(i%2 != 0)
            {
                for(j = 1; j <= m; ++j)
                {
                    putchar('#');
                }
            }
            else if((i/2)%2 != 0)
            {
                for(j = 1; j <= m; ++j)
                {
                    if(j == m) putchar('#');
                    else putchar('.');
                }
            }
            else
            {
                for(j = 1; j <= m; ++j)
                {
                    if(j == 1) putchar('#');
                    else putchar('.');
                }
            }
            putchar('\n');
        }
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
#include <List>
#include <cmath>
#include <algorithm>
#define MaxSize
#define LL long long

using namespace std;

int main()
{
    int n,m;
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
        for(i = 1; i <= n; ++i)
        {
            if(i%2 != 0)
            {
                for(j = 1; j <= m; ++j)
                {
                    putchar('#');
                }
            }
            else if((i/2)%2 != 0)
            {
                for(j = 1; j <= m; ++j)
                {
                    if(j == m) putchar('#');
                    else putchar('.');
                }
            }
            else
            {
                for(j = 1; j <= m; ++j)
                {
                    if(j == m) putchar('.');
                    else putchar('#');
                }
            }
            putchar('\n');
        }
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    char table[51][51];
    int n, m;
    cin >> n >> m;
    int flip = m;
    for (int i = 1; i <= n; i++){
        for (int j = 1, ok = 1; j <= m; j++){
            if (i%2){
                cout << '#';
                continue;
            }
            if (i%2 == 0 && j == flip && ok){
                    cout << '#';
                    flip = (flip == 1 ? m:1);
                    ok = 0;
            }else  cout << '.';

        }
        cout << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    char table[51][51];
    int n, m;
    cin >> n >> m;
    int flip = m;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (i%2) cout << '#';
            if (i%2 == 0 && j!= flip) cout << '.';
            if (i%2 == 0 && j == flip){
                    cout << '#';
                    flip = (flip == 1 ? m:1);
            }
        }
        cout << endl;
    }
    return 0;
}


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

int n, m;

int main(void) {
    cin >> n >> m;
    for (int i=0; i<n; i++) {
	if (i % 2==0) {
	    for (int j=0; j<m; j++) {
		cout << '#';
	    }
	    cout << "\n";
	}
	else if (i % 4==1) {
	    for (int j=0; j<m-1; j++) cout << '.';
	    cout << "#\n"
	}
	else {
	    cout << '#';
	    for (int j=1; j<m; j++) cout << '.';
	    cout << '\n';
	}
    }
    return 0;
}


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

int n, m;

int main(void) {
    cin >> n >> m;
    for (int i=0; i<n; i++) {
	if (i % 2==0) {
	    for (int j=0; j<m; j++) {
		cout << '#';
	    }
	    cout << "\n";
	}
	else if (i % 4==1) {
	    for (int j=0; j<m-1; j++) cout << '.';
	    cout << "#\n";
	}
	else {
	    cout << '#';
	    for (int j=1; j<m; j++) cout << '.';
	    cout << '\n';
	}
    }
    return 0;
}


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

int main()
{
	int n, m, i, j;
	cin >> n >> m;

	for(i=1; i<=n; i++){
		if(i%2 !=  0){
			for(j=0; j<m; j++)
				cout << "#";
			putchar_unlocked('\n');
		}
		else{
			if((i/2)%2 != 0){
				for(j=0; j<m-1; j++)
					cout << ".";
				cout << "#";
				putchar_unlocked('\n');
			}
			else{
				cout << "#";
				for(j=1; j<m; j++)
					cout << ".";
				putchar_unlocked('\n');
			}
		}
	}
	return 0;
}


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

int main()
{
	int n, m, i, j;
	cin >> n >> m;

	for(i=1; i<=n; i++){
		if(i%2 !=  0){
			for(j=0; j<m; j++)
				cout << "#";
			putchar_unlocked('\n');
		}
		else{
			if((i/2)%2 != 0){
				for(j=0; j<m-1; j++)
					cout << ".";
				cout << "#";
				putchar_unlocked('\n');
			}
			else{
				cout << "#";
				for(j=1; j<m; j++)
					cout << ".";
				putchar_unlocked('\n');
			}
		}
	}
	return 0;
}


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

int main(){
	int n, m, i, j;
	cin >> n >> m;

	for(i=1; i<=n; i++){
		if(i%2 !=  0){
			for(j=0; j<m; j++)
				cout << "#";
			putchar_unlocked('\n');
		}
		else{
			if((i/2)%2 != 0){
				for(j=0; j<m-1; j++)
					cout << ".";
				cout << "#";
				putchar_unlocked('\n');
			}
			else{
				cout << "#";
				for(j=1; j<m; j++)
					cout << ".";
				putchar_unlocked('\n');
			}
		}
	}

	return 0;
}


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

int main()
{
	int n, m, i, j;
	cin >> n >> m;

	for(i=1; i<=n; i++){
		if(i%2 !=  0){
			for(j=0; j<m; j++)
				cout << "#";
			cout << '\n';
		}
		else{
			if((i/2)%2 != 0){
				for(j=0; j<m-1; j++)
					cout << ".";
				cout << "#";
				cout << '\n';
			}
			else{
				cout << "#";
				for(j=1; j<m; j++)
					cout << ".";
				cout << '\n';
			}
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <string>
#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define F first
#define S second
#define Check cout << "qwerty" << endl;
#define all(x) x.begin(), x.end()

using namespace std;

const int MaxN = int (1e5);
const int INF = int(1e9);

int n, m, cur;
char ch[111][111];

int main () {
//  freopen ("input.txt","r",stdin);
//  freopen ("output.txt","w",stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 != 0) {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '#';
            }
        } else {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '.';
            }
        }
    }
    for (int i = 2; i <= n; i += 2) {
        if (cur % 2 == 0) {
            ch[i][m] = '#';
        } else {
            ch[i][1] = '#';
        }
        cur++;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << ch[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


##include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <string>
#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define F first
#define S second
#define Check cout << "qwerty" << endl;
#define all(x) x.begin(), x.end()

using namespace std;

const int MaxN = int (1e5);
const int INF = int(1e9);

int n, m, cur;
char ch[111][111];

int main () {
//  freopen ("input.txt","r",stdin);
//  freopen ("output.txt","w",stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 != 0) {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '#';
            }
        } else {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '.';
            }
        }
    }
    for (int i = 2; i <= n; i += 2) {
        if (cur % 2 == 0) {
            ch[i][m] = '#';
        } else {
            ch[i][1] = '#';
        }
        cur++;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << ch[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <string>
#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define F first
#define S second
#define Check cout << "qwerty" << endl;
#define all(x) x.begin(), x.end()

using namespace std;

const int MaxN = int (1e5);
const int INF = int(1e9);

int n, m, cur;
char ch[111][111];

int main () {
//  freopen ("input.txt","r",stdin);
//  freopen ("output.txt","w",stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 != 0) {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '#';
            }
        } else {
            for (int j = 1; j <= m; ++j) {
                ch[i][j] = '.';
            }
        }
    }
    for (int i = 2; i <= n; i += 2) {
        if (cur % 2 == 0) {
            ch[i][m] = '#';
        } else {
            ch[i][1] = '#';
        }
        cur++;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << ch[i][j];
        }
        cout << endl;
    }
    return 0;
}


//#include <iostream>
//#include <algorithm>
//#include <fstream>
//using namespace std;
//long long a, b, c, d;
//long long min(long long x)
//{
//	if (c % 2 == 0)
//	{
//		if (a % x != 0)
//			return max(max(x, a / x + 1), c / 2 - x);
//		else
//			return max(max(x, a / x), c / 2 - x);
//	}
//	else
//	{
//		if (a % x != 0)
//			return max(max(x, a / x + 1), (c + 1) / 2 - x);
//		else
//			return max(max(x, a / x), (c + 1) / 2 - x);
//	}
//}
//long long max(long long x)
//{
//	return min(d / 2 - x, b / x);
//}
//int main()
//{
//	freopen("hall.in", "r", stdin);
//	freopen("hall.out", "w", stdout);
//	long long ans = 0;
//	cin >> a >> b >> c >> d;
//	for (long long i = 1; i * i <= b; i++)
//	{
//		ans += max(0ll,max(i) - min(i) + 1ll);
//	}
//	cout << ans;
//	return 0;
//}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	iostream::sync_with_stdio(0);
	int n, m;
	bool flaq = true;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i % 2 == 0)
				cout << "#";
			else
			{
				if (!flaq)
				{
					cout << "#";
					j++;
					for (; j < m; j++)
						cout << ".";
					flaq = true;
				}
				else
				{
					j++;
					for (; j < m; j++)
						cout << ".";
					cout << "#";
					flaq = false;
				}
			}
		}
		cout << endl;
	}
	return 0;
}


//============================================================================
// Name        : тэмпля.cpp
// Author      : ucyc
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

void printOdd(int stringLength)
{
	for (int i = 0; i < stringLength; i++)
		cout << "#";
	cout << "\n";
	return;
}

void printTwoModFour(int stringLength)
{
	for (int i = 1; i < stringLength; i++)
		cout << ".";
	cout <<"#";
	cout << "\n";
	return;
}

void printZeroModFour(int stringLength)
{
	cout <<"#";
	for (int i = 1; i < stringLength; i++)
		cout << ".";
	cout << "\n";
	return;
}

int main()
{
	int stringHeight = 0;
	int stringLength = 0;

	cin >> stringHeight;
	cin >> stringLength;

	for (int i = 1; i <= stringHeight; i++) {
		if (i % 4 == 0)
			printZeroModFour(stringLength);
		if (i % 4 == 2)
			printTwoModFour(stringLength);
		if (i % 2 == 1)
			printOdd(stringLength);
	}

	return 0;
}


//============================================================================
// Name        : тэмпля.cpp
// Author      : ucyc
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

void printOdd(int stringLength)
{
	for (int i = 0; i < stringLength; i++)
		cout << "#";
	cout << "\n";
	return;
}

void printEven(int stringLength)
{
	for (int i = 1; i < stringLength; i++)
		cout << ".";
	cout <<"#";
	cout << "\n";
	return;
}

int main()
{
	int stringHeight = 0;
	int stringLength = 0;

	cin >> stringHeight;
	cin >> stringLength;

	for (int i = 1; i <= stringHeight; i++) {
		if (i % 2 == 0)
			printEven(stringLength);
		else
			printOdd(stringLength);
	}

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <assert.h>
#include <cctype>
#include <string.h>
using namespace std;

#define INF_MAX 2147483647
#define INF_MIN -2147483647

#define pi acos(-1.0)
#define INF 1e9
#define ll long long

#define For(i, a, b) for( int i = (a); i <= (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define mem(a, s) memset(a, s, sizeof (a))
#define Read() freopen("1.txt", "r", stdin)
#define Write() freopen("2.txt", "w", stdout)
#define sz(c) ((int)(c).size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector <ll> >
typedef pair<int, int> PAIR;
typedef pair<PAIR, int> PAIR2;
string tostring(long long n){ ostringstream ss; ss << n; return ss.str(); }
ll tonumber(string str){ stringstream ss; ss << str; long long n; ss >> n; return n; }

int main()
{
    int r, c, cnt = 1;
    cin >> r >> c;
    For(i, 1, r)
    {
        if (cnt % 2 == 1)
        {
            For(j, 1, c)
            {
                cout << '#';
            }
            cout << endl;
        }
        else if (cnt % 4 == 0)
        {
            cout << '#';
            For(j, 1, c - 1)
            {
                cout << '.';
            }

            cout << endl;

        }
        else if (cnt%2==0)
        {
            For(j, 1, c-1)
            {
                cout << '.';
            }
            cout << '#';
            cout << endl;
        }

        cnt++;

    }

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <assert.h>
#include <cctype>
#include <string.h>
using namespace std;

#define INF_MAX 2147483647
#define INF_MIN -2147483647

#define pi acos(-1.0)
#define INF 1e9
#define ll long long

#define For(i, a, b) for( int i = (a); i <= (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define mem(a, s) memset(a, s, sizeof (a))
#define Read() freopen("1.txt", "r", stdin)
#define Write() freopen("2.txt", "w", stdout)
#define sz(c) ((int)(c).size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector <ll> >
typedef pair<int, int> PAIR;
typedef pair<PAIR, int> PAIR2;
string tostring(long long n){ ostringstream ss; ss << n; return ss.str(); }
ll tonumber(string str){ stringstream ss; ss << str; long long n; ss >> n; return n; }

int main()
{
    int r, c, cnt = 1;
    cin >> r >> c;
    For(i, 1, r)
    {
        if (cnt % 2 == 1)
        {
            For(j, 1, c)
            {
                cout << '#';
            }
            cout << endl;
        }
        else
        {
            For(j, 1, c-1)
            {
                cout << '.';
            }
            cout << '#';
            cout << endl;
        }
        cnt++;

    }

}


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

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;

#define REP(i,s,t) for(int i=(s);i<(t);i++)
#define FILL(x,v) memset(x,v,sizeof(x))

const int INF = (int)1E9;
#define MAX 300

int n,m;

int main (int argc, char const* argv[])
{
	scanf("%d%d",&n,&m);
	for (int i = 1; i <= n; i += 1)
	{
		if(i%2 != 0){
			for (int j = 0; j < m; j += 1)
			{
				cout<<"#";
			}
			cout << endl;
		}
		else{
			if(i % 4 == 0){
			for (int j = 0; j < m-1; j += 1)
			{
				cout<<".";
			}
			cout <<"#" <<endl;
			}
			else {
			cout <<"#";
			for (int j = 0; j < m-1; j += 1)
			{
				cout<<".";
			}
			cout <<endl;
			}
		}
	}
	return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;

#define REP(i,s,t) for(int i=(s);i<(t);i++)
#define FILL(x,v) memset(x,v,sizeof(x))

const int INF = (int)1E9;
#define MAX 300

int n,m;

int main (int argc, char const* argv[])
{
	scanf("%d%d",&n,&m);
	for (int i = 1; i <= n; i += 1)
	{
		if(i%2 != 0){
			for (int j = 0; j < m; j += 1)
			{
				cout<<"#";
			}
			cout << endl;
		}
		else{
			if(i % 4 != 0){
			for (int j = 0; j < m-1; j += 1)
			{
				cout<<".";
			}
			cout <<"#" <<endl;
			}
			else {
			cout <<"#";
			for (int j = 0; j < m-1; j += 1)
			{
				cout<<".";
			}
			cout <<endl;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int nb1,nb2;
    cin>>nb1;
    cin>>nb2;
    bool test=true;
    for(int i=0;i<nb1;i++)
    {
        for(int j=0;j<nb2;j++)
        {

            if((i+1)%2!=0)
                cout<<"#";
            else
            {
                if((j==nb2-1)||(j==0))
                {if((test)&&(j==nb2-1))
                {cout<<"#";}

                else if((!test)&&(j==0))
                {cout<<"#";}

                    else
                        {cout<<".";}
                }
                else
                    cout<<".";
            }
        if (j==nb2-1)
            cout<<endl;

        }
         if((i+1)%2==0)
                test=!test;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int days,instru;

    cin>>instru;
    cin>>days;
    int t1[instru];
     vector<int> t ;
     t.resize(instru);

    for (int i=0;i<instru;i++)
    {
        cin>>t[i];
        t1[i]=t[i];

    }

    sort(t.begin(), t.end());
    int cmp=0;
    int day=0;
    while ((cmp<instru)&&(days>0))
    {
        if (t[cmp]<=days)
        {
            days-=t[cmp];
            cmp++;
        }else
        days=0;

    }
    cout<<cmp<<endl;
    if(cmp!=0)
    {
        if (cmp==1)
            cout<<1;
        else
        {
            for (int i=0;i<cmp;i++)
             {
                   int x=t[i],j=0;
                   bool found=false;
                   while(found==(false))
                    {if(x==t1[j])
                    {found=true;
                    cout<<j+1<<" ";
                    t1[j]=-1;}
                     j++;}

              }

        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int nb1,nb2;
    cin>>nb1>>nb2;
    bool test=true;
    for(int i=0;i<nb1;i++)
    {
        for(int j=0;j<nb2;j++)
        {

            if((i+1)%2!=0)
                cout<<"#";
            else
            {
                if((j==nb2-1)||(j==0))
                {if((test)&&(j==nb2-1))
                {cout<<"#";

                }
                else if((!test)&&(j==0))
                    {cout<<"#";

                    }
                    else
                        cout<<".";
                }
                else
                    cout<<".";
            }
        if (j==nb2-1)
            cout<<endl;
            if((i+1)%2==0)
                test=!test;
        }
    }
    return 0;
}


#include <iostream>
#include<cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <strings.h>

using namespace std;
int main()
{
    int n  , m , counter = 0 , counter1 = 0 , number = 0 , found = 0 , flag = 0;
    scanf("%d %d",&n,&m);
    for (counter = 1 ; counter <= n ; counter++)
    {
        flag = 0;
        found = 0;
        for (counter1 = 1 ; counter1 <= m && found == 0; counter1++)
        {
            if (counter % 2 != 0 && flag == 0)
            {
                number++;
                flag = 1;
            }
            if (counter % 2 != 0)
            {
                printf("#");
            }
            else if (number % 2 != 0)
            {
                int i = 0;
                for (i = 1 ; i < m ; i++)
                {
                    printf(".");
                }
                printf("#");
                found = 1;
            }
            else
            {
                int s = 0;
                printf("#");
                for (s = 1 ; s < m ; s++)
                {
                    printf(".");
                }
                found = 1;
            }
        }
        printf("\n");
    }
    return 0;
}