#include<bits/stdc++.h>
using namespace std;
#define maxn 200010
#define ll long long
int n;
ll a,b;
struct P
{
    ll x,y;
    bool operator < (const P& c)const
    {
        if(a*x-y!=a*c.x-c.y)return a*x-y<a*c.x-c.y;
        return x<c.x;
    }
}v[maxn];
vector<int> vv;
main()
{
    scanf("%d%lld%lld",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d%lld%lld",&x,&v[i].x,&v[i].y);
    }
    sort(v+1,v+n+1);
    for(int i=1;i<=n;i++)printf("%lld %lld: %lld\n",v[i].x,v[i].y,a*v[i].x-v[i].y);
    ll ans=0;
    int num=0,cur=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=1 && v[i-1].x==v[i].x && v[i-1].y==v[i].y)cur++,num++;
        else if(i==1 || a*v[i-1].x-v[i-1].y<a*v[i].x-v[i].y)
        {
            vv.push_back(cur);
            //printf("%d\n",num);
            ans+=1ll*num*(num-1);
            num=1,cur=1;
            for(int s : vv)ans-=1ll*s*(s-1);
            //for(int s : vv)printf("%d ",s);puts("");
            vv.clear();
        }
        else
        {
            num++;
            vv.push_back(cur);
            cur=1;
        }
    }
    vv.push_back(cur);
    ans+=1ll*num*(num-1);
    for(int s : vv)ans-=1ll*s*(s-1);
    //printf("%d\n",num);
    //for(int s : vv)printf("%d ",s);puts("");
    //for(int s : vv)printf("%d ",s);puts("");
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200010
#define ll long long
int n;
ll a,b;
struct P
{
    ll x,y;
    bool operator < (const P& c)const
    {
        if(a*x-y!=a*c.x-c.y)return a*x-y<a*c.x-c.y;
        return x<c.x;
    }
}v[maxn];
vector<int> vv;
main()
{
    scanf("%d%lld%lld",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d%lld%lld",&x,&v[i].x,&v[i].y);
    }
    sort(v+1,v+n+1);
    //for(int i=1;i<=n;i++)printf("%lld %lld: %lld\n",v[i].x,v[i].y,a*v[i].x-v[i].y);
    ll ans=0;
    int num=0,cur=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=1 && v[i-1].x==v[i].x && v[i-1].y==v[i].y)cur++,num++;
        else if(i==1 || a*v[i-1].x-v[i-1].y<a*v[i].x-v[i].y)
        {
            //printf("%d\n",num);
            ans+=1ll*num*(num-1);
            num=1,cur=1;
            for(int s : vv)ans-=1ll*s*(s-1);
            vv.clear();
        }
        else
        {
            num++;
            vv.push_back(cur);
            cur=1;
        }
    }
    vv.push_back(cur);
    ans+=1ll*num*(num-1);
    for(int s : vv)ans-=1ll*s*(s-1);
    //for(int s : vv)printf("%d ",s);puts("");
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > II;

map<ll,ll> d;
map<II,ll> d1;
ll Vx[200005],Vy[200006];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    FOR (i,1,n){
        ll x;
        cin>>x>>Vx[i]>>Vy[i];
        d1[II(Vx[i],Vy[i])]++;
        d[Vy[i]-a*Vx[i]]++;
    }
    ll res=0;
    FOR (i,1,n){
        res+=d[Vy[i]-a*Vx[i]]-d1[II(Vx[i],Vy[i])];
    }
    cout<<res<<endl;
         return 0;
}


#include <bits/stdc++.h>

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

struct line {
    ll a, b;
    line() {a=b=0;}
    line (ll m, ll n){a=m;b=n;}
};

bool operator < (line m, line n){
    return m.a*n.b<m.b*n.a;
}

map<line,ll> d;
map<ll,ll> dd;
line l[200005];
ll Vx[200005],Vy[200005];
ll A,B;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    FOR (i,1,n){
        ll x;
        cin>>x>>Vx[i]>>Vy[i];
        if (Vx[i]*a==Vy[i]){
            if (Vx[i]==0 && Vy[i]==0){
                A++;
            }
            else{
                B++;
                dd[Vx[i]]++;
            }
        }
        else{
            d[line(Vx[i],Vy[i])]++;
        }
    }
    ll res=2*A*B;
    FOR (i,1,n){
        if(Vx[i] || Vy[i]){
            if (Vx[i]*a==Vy[i]){
                res+=B-1-(dd[Vx[i]]-1);
                res+=n-A-B;
            }
            else{
                res+=n-A-1-(d[line(Vx[i],Vy[i])]-1);
            }
        }
    }
    cout<<res<<endl;
         return 0;
}


#include <bits/stdc++.h>

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > II;

ll gcd1(ll a, ll b){
    if (b==0) return a;
    if (a==0) return b;
    if (b>=a) return gcd1(b%a,a);
    return gcd1(a%b,b);
}

inline ll gcd(ll a, ll b){
    return gcd1(abs(a),abs(b));
}

struct point{
    ll x,y;
    point (){x=y=0;}
    point (ll a, ll b) {
        x=a;y=b;
    }
};

struct line {
    ll a,b,c;
    line (){a=b=c=0;}
    line (point A,point B){
        a = B.y - A.y;
        b = A.x - B.x;
        c = -(a * A.x + b * A.y);
        //cout<<a<<" "<<b<<" "<<c<<endl;
        ll u=gcd(a,b);
        u=gcd(u,c);
        //cout<<u<<endl;

        a/=u; b/=u; c/=u;
        if (a){
            if (a<0) {
                a*=-1;
                b*=-1;
                c*=-1;
            }
        }
        else{
            if (b<0){b*=-1; c*=-1;}
        }
    }
};

bool operator==(line m, line n){
    return (m.a==n.a && m.b==n.b && m.c==n.c);
}
bool operator < (line m,line n){
    if (m.a==n.a && m.b==n.b) return m.c<n.c;
    if (m.a==n.a) return m.b<n.b;
    return m.a<n.a;
}
map<line,int> d;
map<II,int> d1;
map<ll,int> dd;
line L,li[200005];
ll V1[200005],V2[200005];

bool check(int i, int j){
    //cout<<i<<" "<<j<<endl;
    //cout<<li[i].a<<" "<<li[i].b<<" "<<li[i].c<<endl;
    //cout<<li[j].a<<" "<<li[j].b<<" "<<li[j].c<<endl;
    //cout<<L.a<<" "<<L.b<<" "<<L.c<<endl;
    if (li[i]==line()){
        if (li[j]==line()) return 0;
        if (li[j]==L) return 1;
    }
    if (li[j]==line()){
        if (li[i]==L) return 1;
    }
    if (li[i]==li[j]) {
        if (V1[i]==V1[j]) return 0;
        return 1;
    }
    if (li[i].a*li[j].b==li[i].b*li[j].a) return 0;
    return 1;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    L=line(point(0,b),point(1,a+b));
    ll res=0,ca=0,R=0;
    FOR (i,1,n){
        ll x,Vx,Vy;
        cin>>x>>Vx>>Vy;
        V1[i]=Vx;
        V2[i]=Vy;
        if (Vx || Vy){
            ll y=a*x+b;
            line l=line(point(x,y),point(x+Vx,y+Vy));
            d[l]++;
            ll q=gcd(l.a,l.b);
            d1[II(l.a/q,l.b/q)]++;
            li[i]=l;
            if (l==L) {ca++;dd[Vx]++;}
        }
        else {
            R++;
        }
    }
    //cout<<L.a<<" "<<L.b<<" "<<L.c<<endl;
    FOR (i,1,n){
        FOR (j,i+1,n){
            if(check(i,j)) res+=2;
        }
    }
    cout<<res<<endl;
         return 0;
}


#include <bits/stdc++.h>

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > II;

ll gcd1(ll a, ll b){
    if (b==0) return a;
    if (a==0) return b;
    if (b>=a) return gcd1(b%a,a);
    return gcd1(a%b,b);
}

inline ll gcd(ll a, ll b){
    return gcd1(abs(a),abs(b));
}

struct point{
    ll x,y;
    point (){x=y=0;}
    point (ll a, ll b) {
        x=a;y=b;
    }
};

struct line {
    ll a,b,c;
    line (){a=b=c=0;}
    line (point A,point B){
        a = B.y - A.y;
        b = A.x - B.x;
        c = -(a * A.x + b * A.y);
        //cout<<a<<" "<<b<<" "<<c<<endl;
        ll u=gcd(a,b);
        u=gcd(u,c);
        //cout<<u<<endl;

        a/=u; b/=u; c/=u;
        if (a){
            if (a<0) {
                a*=-1;
                b*=-1;
                c*=-1;
            }
        }
        else{
            if (b<0){b*=-1; c*=-1;}
        }
    }
};

bool operator==(line m, line n){
    return (m.a==n.a && m.b==n.b && m.c==n.c);
}
bool operator < (line m,line n){
    if (m.a==n.a && m.b==n.b) return m.c<n.c;
    if (m.a==n.a) return m.b<n.b;
    return m.a<n.a;
}
map<line,int> d;
map<II,int> d1;
map<ll,int> dd;
line L,li[200005];
ll V1[200005],V2[200005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    line L=line(point(0,b),point(1,a+b));
    ll res=0,ca=0,R=0;
    FOR (i,1,n){
        ll x,Vx,Vy;
        cin>>x>>Vx>>Vy;
        V1[i]=Vx;
        V2[i]=Vy;
        if (Vx || Vy){
            ll y=a*x+b;
            line l=line(point(x,y),point(x+Vx,y+Vy));
            d[l]++;
            ll q=gcd(l.a,l.b);
            d1[II(l.a/q,l.b/q)]++;
            li[i]=l;
            if (l==L) {ca++;dd[Vx]++;}
        }
        else {
            R++;
        }
    }
    res=R*ca*2;
    FOR (i,1,n){
        if (li[i].a || li[i].b){
            ll q=gcd(li[i].a,li[i].b);
            res+=n-R-1-d1[II(li[i].a/q,li[i].b/q)]+d[li[i]];
            //cout<<res<<endl;
            if (li[i]==L){
                res-=dd[V1[i]]-1;
            }
            //cout<<res<<endl;
            //cout<<i<<" "<<n-R-1-d1[II(li[i].a/q,li[i].b/q)]+d[li[i]]<<endl;
            //cout<<d1[II(li[i].a/q,li[i].b/q)]<<" "<<d[li[i]]<<endl;
            //cout<<li[i].a<<" "<<li[i].b<<" "<<li[i].c<<endl;
        }
    }
    cout<<res<<endl;
         return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define repLL(i,a,b) for(LL i=(LL)a;i<(LL)b;i++)
#define perLL(i,a,b) for(LL i=(LL)a;i>(LL)b;i--)
#define debug5(a,b,c,d,e) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<" "<<#e<<": "<<e<<endl;
#define debug4(a,b,c,d)  cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<endl;
#define debug3(a,b,c) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
#define debug2(a,b) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<typename T>
void dbg(T a)
{
      #ifdef LOCAL
            cerr<<a<<"\n";
      #endif
}

template<typename T, typename ...Arg>
void dbg(T a,Arg ...arg)
{
      #ifdef LOCAL
            cerr<<a<<" ";
            dbg(arg...);
      #endif
}

const int maxn=(1e6)+7;
const int inf=(1e9)+7;
const LL LLinf=(1e18)+7;
const LD eps=1e-9;
const LL mod=1e9+7;

// ***************************** CODE ***************************** //

LL pref[maxn];
map<LL, LL > mapa;
map<PLL, LL> ile;
int main()
{
      _upgrade
      int n, a, b;
      cin>>n>>a>>b;
      LL res = 0LL;
      for(int i = 0 ;i < n;i++)
      {
        LL x, c, d;
        cin>>x>>c>>d;
        res += mapa[a * c - d] - ile[{c, d}];
        mapa[a * c - d]++;
        ile[{c, d}]++;
      }
      cout<<res * 2LL;
      return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define repLL(i,a,b) for(LL i=(LL)a;i<(LL)b;i++)
#define perLL(i,a,b) for(LL i=(LL)a;i>(LL)b;i--)
#define debug5(a,b,c,d,e) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<" "<<#e<<": "<<e<<endl;
#define debug4(a,b,c,d)  cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<endl;
#define debug3(a,b,c) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
#define debug2(a,b) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<typename T>
void dbg(T a)
{
      #ifdef LOCAL
            cerr<<a<<"\n";
      #endif
}

template<typename T, typename ...Arg>
void dbg(T a,Arg ...arg)
{
      #ifdef LOCAL
            cerr<<a<<" ";
            dbg(arg...);
      #endif
}

const int maxn=(1e6)+7;
const int inf=(1e9)+7;
const LL LLinf=(1e18)+7;
const LD eps=1e-9;
const LL mod=1e9+7;

// ***************************** CODE ***************************** //

LL pref[maxn];
map<PII, LL> mapa;

void redukuj(LL& a, LL& b)
{
  if(a == 0 && b == 0)
    return;
  LL gc = abs(__gcd(a, b));
  a /= gc;
  b /= gc;
}

int main()
{
      _upgrade
      int n, a, b;
      cin>>n>>a>>b;
      int cur = n;
      for(int i = 0 ;i < n;i++)
      {
        LL a, b, x;
        cin>>x>>a>>b;
        redukuj(a, b);
        // cerr<<a<<" "<<b<<endl;
        if(a != 0 || b != 0)
          mapa[{a, b}]++;
        else
         cur--;
      }
      LL res = cur * (LL)(cur - 1 ) / 2;
      for(auto s : mapa)
        res -= s.se * (LL) (s.se - 1) / 2LL;
      cout<<res * 2LL;
      return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define repLL(i,a,b) for(LL i=(LL)a;i<(LL)b;i++)
#define perLL(i,a,b) for(LL i=(LL)a;i>(LL)b;i--)
#define debug5(a,b,c,d,e) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<" "<<#e<<": "<<e<<endl;
#define debug4(a,b,c,d)  cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<endl;
#define debug3(a,b,c) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
#define debug2(a,b) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<typename T>
void dbg(T a)
{
      #ifdef LOCAL
            cerr<<a<<"\n";
      #endif
}

template<typename T, typename ...Arg>
void dbg(T a,Arg ...arg)
{
      #ifdef LOCAL
            cerr<<a<<" ";
            dbg(arg...);
      #endif
}

const int maxn=(1e6)+7;
const int inf=(1e9)+7;
const LL LLinf=(1e18)+7;
const LD eps=1e-9;
const LL mod=1e9+7;

// ***************************** CODE ***************************** //

LL pref[maxn];
map<LL, VPII > mapa;

void redukuj(LL& a, LL& b)
{
  if(a == 0 && b == 0)
    return;
  LL gc = abs(__gcd(a, b));
  a /= gc;
  b /= gc;
}

int main()
{
      _upgrade
      int n, a, b;
      cin>>n>>a>>b;
      int cur = n;
      for(int i = 0 ;i < n;i++)
      {
        LL x, c, d;
        cin>>x>>c>>d;
        redukuj(c, d);
        mapa[a * c - d].pb({c, d});
      }
      LL res = 0LL;
      for(auto s : mapa)
      {
        sort(ALL(s.se));
        VI V;
        res += (LL)SZ(s.se) *(LL)(SZ(s.se) - 1) / 2LL;
        for(int i = 0 ;i < SZ(s.se);i++)
        {
          if(i > 0 && s.se[i] == s.se[i - 1])
            V.back()++;
          else
            V.pb(1);
        }
        for(auto v : V)
          res -= v * (LL)( v - 1 ) / 2LL;
      }
      cout<<res * 2LL;
      return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef double db;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(ll &a, ll b){a = (a+b)%MOD;}
void _sub(ll &a, ll b){a = (a+MOD-b)%MOD;}
void _mul(ll &a, ll b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pow(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll powM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k, T, a, b;
ll Vx[N], Vy[N], x[N];
multiset<ll> vis;
multiset<pll> vecs;
int main(){
//	freopen("1", "r", stdin);
	sc(n),sc(a),sc(b);
	ll ans = 0;
	rep(i,0,n-1){
		sc64(x[i]),sc64(Vx[i]),sc64(Vy[i]);
		ll x = Vy[i]-a*Vx[i];
		ans += vis.count(x);
		ans -= vecs.count(mp(Vx[i],Vy[i]));
		vis.insert(x);
		vecs.insert(mp(Vx[i],Vy[i]));
	}
	pr64(ans<<1),ln;
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
		  printf("Case #%d: ", ca+1);
	}
*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef double db;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 200010
#define M 1024
#define MOD 1000000007
void _add(ll &a, ll b){a = (a+b)%MOD;}
void _sub(ll &a, ll b){a = (a+MOD-b)%MOD;}
void _mul(ll &a, ll b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pow(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll powM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n;
ll a, b;
int Vx[N], Vy[N], x[N];
//multiset<ll> vis;
//multiset<pll> vecs;
map<ll,int> vis;
map<pii,int> vecs;
int main(){
//	freopen("1", "r", stdin);
	sc(n),sc64(a),sc64(b);
	ll ans = 0;
	rep(i,0,n-1){
		sc(x[i]),sc(Vx[i]),sc(Vy[i]);
		ll x = (ll)Vy[i]-a*(ll)Vx[i];
		if(vis.find(x) != vis.end()){
			ans += vis[x];
			vis[x]++;
//			ans += vis.count(x);
		}else vis[x] = 1;
		pii t = mp(Vx[i],Vy[i]);
		if(vecs.find(t) != vecs.end()){
			ans -= vecs[t];
			vecs[t]++;
//			ans -= vecs.count(mp(Vx[i],Vy[i]));
		}else vecs[t] = 1;
//		vis.insert(x);
//		vecs.insert(mp(Vx[i],Vy[i]));
	}
	pr64(ans<<1),ln;
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
		  printf("Case #%d: ", ca+1);
	}
*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef double db;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(ll &a, ll b){a = (a+b)%MOD;}
void _sub(ll &a, ll b){a = (a+MOD-b)%MOD;}
void _mul(ll &a, ll b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pow(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll powM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n;
ll a, b;
int Vx[N], Vy[N], x[N];
//multiset<ll> vis;
//multiset<pll> vecs;
map<ll,int> vis;
map<pii,int> vecs;
int main(){
//	freopen("1", "r", stdin);
	sc(n),sc64(a),sc64(b);
	ll ans = 0;
	rep(i,0,n-1){
		sc(x[i]),sc(Vx[i]),sc(Vy[i]);
		ll x = (ll)Vy[i]-a*(ll)Vx[i];
		if(vis.find(x) != vis.end()){
			ans += vis[x];
			vis[x]++;
//			ans += vis.count(x);
		}else vis[x] = 1;
		pii t = mp(Vx[i],Vy[i]);
		if(vecs.find(t) != vecs.end()){
			ans -= vecs[t];
			vecs[t]++;
//			ans -= vecs.count(mp(Vx[i],Vy[i]));
		}else vecs[t] = 1;
//		vis.insert(x);
//		vecs.insert(mp(Vx[i],Vy[i]));
	}
	pr64(ans<<1),ln;
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
		  printf("Case #%d: ", ca+1);
	}
*/
	return 0;
}


#include<map>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
ll n,A,B,ans[200005],len,as;
struct node
{
	ll x,v1,v2;
}a[200005];
struct node1
{
	ll x,y;
}b[200005];
map<ll,int>q;
bool comp(node a,node b)
{
	if(a.v1==b.v1)
		return a.v2<b.v2;
	return a.v1<b.v1;
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i].x,&a[i].v1,&a[i].v2);
	sort(a+1,a+n+1,comp);
	int num=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i].v1==a[i-1].v1 && a[i].v2==a[i-1].v2)
			num++;
		else
			as-=num*(num-1),num=1;
	}
	as-=num*(num-1);
	for(int i=1;i<=n;i++)
		b[i].x=a[i].x+a[i].v1,b[i].y=A*a[i].x+B+a[i].v2;
	for(int i=1;i<=n;i++)
	{
		ll tmp=b[i].y-A*b[i].x;
		if(q[tmp]==0)
			ans[++len]=tmp;
		q[tmp]++;
	}
	for(int i=1;i<=len;i++)
		as+=q[ans[i]]*(q[ans[i]]-1);
	printf("%lld\n",as);
	return 0;
}


#include<map>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
ll n,A,B,ans[200005],len,as;
struct node
{
	ll x,v1,v2;
}a[200005];
struct node1
{
	ll x,y;
}b[200005];
map<ll,int>q;
bool comp(node a,node b)
{
	if(a.v1==b.v1)
		return a.v2<b.v2;
	return a.v1<b.v1;
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i].x,&a[i].v1,&a[i].v2);
	sort(a+1,a+n+1,comp);
	ll num=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i].v1==a[i-1].v1 && a[i].v2==a[i-1].v2)
			num++;
		else
			as-=num*(num-1),num=1;
	}
	as-=num*(num-1);
	for(int i=1;i<=n;i++)
		b[i].x=a[i].x+a[i].v1,b[i].y=A*a[i].x+B+a[i].v2;
	for(int i=1;i<=n;i++)
	{
		ll tmp=b[i].y-A*b[i].x;
		if(q[tmp]==0)
			ans[++len]=tmp;
		q[tmp]++;
	}
	for(int i=1;i<=len;i++)
		as+=q[ans[i]]*(q[ans[i]]-1);
	printf("%lld\n",as);
	return 0;
}


#include<map>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
ll n,A,B,ans[200005],len,as;
struct node
{
	ll x,v1,v2;
}a[200005];
struct node1
{
	ll x,y;
}b[200005];
map<ll,ll>q;
bool comp(node a,node b)
{
	if(a.v1==b.v1)
		return a.v2<b.v2;
	return a.v1<b.v1;
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i].x,&a[i].v1,&a[i].v2);
	sort(a+1,a+n+1,comp);
	ll num=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i].v1==a[i-1].v1 && a[i].v2==a[i-1].v2)
			num++;
		else
			as-=num*(num-1),num=1;
	}
	as-=num*(num-1);
	for(int i=1;i<=n;i++)
		b[i].x=a[i].x+a[i].v1,b[i].y=A*a[i].x+B+a[i].v2;
	for(int i=1;i<=n;i++)
	{
		ll tmp=b[i].y-A*b[i].x;
		if(q[tmp]==0)
			ans[++len]=tmp;
		q[tmp]++;
	}
	for(int i=1;i<=len;i++)
		as+=q[ans[i]]*(q[ans[i]]-1);
	printf("%lld\n",as);
	return 0;
}


#include<map>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
ll n,A,B,ans[200005],len,as;
struct node
{
	ll x,v1,v2;
}a[200005];
struct node1
{
	ll x,y;
}b[200005];
map<ll,ll>q;
bool comp(node a,node b)
{
	if(a.v1==b.v1)
		return a.v2<b.v2;
	return a.v1<b.v1;
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i].x,&a[i].v1,&a[i].v2);
	sort(a+1,a+n+1,comp);
	int num=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i].v1==a[i-1].v1 && a[i].v2==a[i-1].v2)
			num++;
		else
			as-=num*(num-1),num=1;
	}
	as-=num*(num-1);
	for(int i=1;i<=n;i++)
		b[i].x=a[i].x+a[i].v1,b[i].y=A*a[i].x+B+a[i].v2;
	for(int i=1;i<=n;i++)
	{
		ll tmp=b[i].y-A*b[i].x;
		if(q[tmp]==0)
			ans[++len]=tmp;
		q[tmp]++;
	}
	for(int i=1;i<=len;i++)
		as+=q[ans[i]]*(q[ans[i]]-1);
	printf("%lld\n",as);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=1e5+10;
using namespace std;
map<ll,ll>ma;
map<ll,ll>::iterator ite;
map<pair<ll,ll>,ll>mt;
map<pair<ll,ll>,ll>::iterator it;
int main(){
	int n;ll a,b;
	scanf("%d%lld%lld",&n, &a, &b);
	ll x,v1,v2;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld%lld",&x,&v1,&v2);
		ma[a*v1-v2]++;
		mt[make_pair(v2,v1)]++;
	}
	ll ans=0;
	for(ite=ma.begin();ite!=ma.end();ite++){
		if((ite)->second==1) continue;
		ll t=(*ite).second;
		ans+=t*(t-1);
	}
	for(it=mt.begin();it!=mt.end();it++) ans-=(it->second)*(it->second-1);
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=1e5+10;
using namespace std;
map<ll,int>ma;
map<ll,int>::iterator ite;
map<pair<ll,ll>,int>mt;
map<pair<ll,ll>,int>::iterator it;
int main(){
	int n;ll a,b;
	scanf("%d%lld%lld",&n, &a, &b);
	ll x,v1,v2;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld%lld",&x,&v1,&v2);
		ma[a*v1-v2]++;
		mt[make_pair(v2,v1)]++;
	}
	ll ans=0;
	for(ite=ma.begin();ite!=ma.end();ite++){
		if((ite)->second==1) continue;
		ll t=(*ite).second;
		ans+=t*(t-1);
	}
	for(it=mt.begin();it!=mt.end();it++) ans-=(it->second)*(it->second-1);
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=1e5+10;
using namespace std;
map<ll,int>ma;
map<ll,int>::iterator ite;
int main(){
	int n;ll a,b;
	scanf("%d%lld%lld",&n, &a, &b);
	ll x,v1,v2;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld%lld",&x,&v1,&v2);
		ma[a*v1-v2]++;
	}
	ll ans=0;
	for(ite=ma.begin();ite!=ma.end();ite++){
		if((ite)->second==1||(ite)->first==0) continue;
		ll t=(*ite).second;
		ans+=t*2;
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;

map<ll,int> ma;
map<ll,int> zx;
map<ll,int> zy;
map<ll,map<ll,int> > xy;

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ll x,v1,v2;
		cin >> x >> v1 >> v2;
		ans += 2*(ma[v2-a*v1]-zx[v1]-zy[v2]+xy[v1][v2]);
		ma[v2-a*v1]++;
		zx[v1]++;
		zy[v2]++;
		xy[v1][v2]++;
	}
	cout << ans << '\n';
	return 0;
}


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

typedef long long ll;

map<ll,int> ma;
map<ll,map<ll,int> > xy;

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ll x,v1,v2;
		cin >> x >> v1 >> v2;
		ll t = 2*(ma[v2-a*v1]-xy[v1][v2]);
		if( t > 0 ) ans += t;
		ma[v2-a*v1]++;
		xy[v1][v2]++;
	}
	cout << ans << '\n';
	return 0;
}


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

typedef long long ll;

map<ll,int> ma;
map<ll,int> zx;
map<ll,int> zy;
map<ll,map<ll,int> > xy;

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ll x,v1,v2;
		cin >> x >> v1 >> v2;
		ll t = 2*(ma[v2-a*v1]-zx[v1]-zy[v2]+xy[v1][v2]);
		if( t > 0 ) ans += t;
		ma[v2-a*v1]++;
		zx[v1]++;
		zy[v2]++;
		xy[v1][v2]++;
	}
	cout << ans << '\n';
	return 0;
}


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

typedef long long ll;

map<ll,int> ma;
map<ll,int> zx;
map<ll,int> zy;
map<ll,map<ll,int> > xy;

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ll x,v1,v2;
		cin >> x >> v1 >> v2;
		ll t = 2*(ma[v2-a*v1]-zx[v1]-zy[v2]+xy[v1][v2]);
		if( t > 0 ) ans += 2 * t;
		ma[v2-a*v1]++;
		zx[v1]++;
		zy[v2]++;
		xy[v1][v2]++;
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
    if(a < b)
        swap(a, b);

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

int main(){

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

    map< pair<int, int>, int > vec;

    int x, vx, vy;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &x, &vx, &vy);
        int div = gcd(abs(vx), abs(vy));

        if(div != 0){
            vx /= div;
            vy /= div;
        }

        if(vx < 0){
            vx *= -1;
            vy *= -1;
        }

        vec[{vx, vy}]++;
    }

    long long ans = 0;

    for(auto p : vec){
        int cnt = p.second;
        ans += cnt * (n - cnt);
    }

    printf("%lld", ans);

}


#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
    if(a < b)
        swap(a, b);

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

int main(){

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

    map<long long, int> vec;
    map< pair<int, int>, int > sim;
    long long ans = 0;

    int x, vx, vy;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &x, &vx, &vy);

        ans += vec[1ll * a * vx - 1ll * vy] - sim[{vx, vy}];

        vec[1ll * a * vx - 1ll * vy]++;
        sim[{vx, vy}]++;
    }

    printf("%lld", 2 * ans);

}


#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
    if(a < b)
        swap(a, b);

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

int main(){

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

    map<long long, int> vec;
    map< pair<int, int>, int > sim;
    long long ans = 0;

    int x, vx, vy;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &x, &vx, &vy);

        ans += vec[1ll * a * vx - vy] - sim[{vx, vy}];

        vec[a * vx - vy]++;
        sim[{vx, vy}]++;
    }

    printf("%lld", 2 * ans);

}


#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
    if(a < b)
        swap(a, b);

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

int main(){

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

    map<long long, int> vec;
    map< pair<int, int>, int > sim;
    long long ans = 0;

    int x, vx, vy;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &x, &vx, &vy);

        ans += vec[a * vx - vy] - sim[{vx, vy}];

        vec[a * vx - vy]++;
        sim[{vx, vy}]++;
    }

    printf("%lld", 2 * ans);

}


#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
    if(a < b)
        swap(a, b);

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

int main(){

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

    map< pair<int, int>, int > vec;

    int x, vx, vy;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &x, &vx, &vy);
        int div = gcd(abs(vx), abs(vy));

        if(div != 0){
            vx /= div;
            vy /= div;
        }

        vec[{vx, vy}]++;
    }

    long long ans = 0;

    for(auto p : vec){
        int cnt = p.second;
        ans += cnt * (n - cnt);
    }

    printf("%lld", ans);

}


#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;
typedef long double Int;

int k, n;

map<pair<int, int>, int> M;

Int v[N];

Int sqr(Int x) { return x * x; }

bool cmp(Int a, Int b) {
	if (fabs(a - b) < 1e-9) return 1;
	return b > 1e-9 && fabs(a / b - 1) < 1e-9;
}

int main() {

	scanf("%d%d%*d", &n, &k);

	LL ans = 0;
	For(i, 1, n) {
		int x, y;
		scanf("%*d%d%d", &x, &y);

		int sig = 1;
		if (y < 1ll * k * x) sig = -1;

		ans -= M[make_pair(x, y)];
		M[make_pair(x, y)]++;
		v[i] = sig * ((sqr(x) + sqr(y)) * (sqr(k) + 1) - sqr(x + (Int)k * y));
	}

	sort(v + 1, v + n + 1);
	For(i, 1, n) {
		int r = i;
		while (cmp(v[r + 1], v[i]) && r < n) ++r;
		ans += 1ll * (r - i + 1) * (r - i) / 2;
		i = r;
	}

	cout << ans * 2 << endl;

	return 0;
}


#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;
typedef __int128 Int;

int k, n;

map<pair<int, int>, int> M;

Int v[N];

Int sqr(Int x) { return x * x; }

int main() {

	scanf("%d%d%*d", &n, &k);

	LL ans = 0;
	For(i, 1, n) {
		int x, y;
		scanf("%*d%d%d", &x, &y);

		int sig = 1;
		if (y < 1ll * k * x) sig = -1;

		ans -= M[make_pair(x, y)];
		M[make_pair(x, y)]++;
		v[i] = sig * ((sqr(x) + sqr(y)) * (sqr(k) + 1) - sqr(x + (Int)k * y));
	}

	sort(v + 1, v + n + 1);
	For(i, 1, n) {
		int r = i;
		while (v[r + 1] == v[i] && r < n) ++r;
		ans += 1ll * (r - i + 1) * (r - i) / 2;
		i = r;
	}

	cout << ans * 2 << endl;

	return 0;
}


#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;
typedef long long Int;

int k, n;

map<pair<int, int>, int> M;

Int v[N];

int main() {

	scanf("%d%d%*d", &n, &k);

	LL ans = 0;
	For(i, 1, n) {
		int x, y;
		scanf("%*d%d%d", &x, &y);

		ans -= M[make_pair(x, y)];
		M[make_pair(x, y)]++;
		v[i] = 1ll * k * x - y;
	}

	sort(v + 1, v + n + 1);
	For(i, 1, n) {
		int r = i;
		while (v[r + 1] == v[i] && r < n) ++r;
		ans += 1ll * (r - i + 1) * (r - i) / 2;
		i = r;
	}

	cout << ans * 2 << endl;

	return 0;
}


//思路没问题？（是不是精度爆了啊。
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
template<typename T> void cmin(T &x,T y){ x=y<x?y:x; }
template<typename T> void cmax(T &x,T y){ x=y>x?y:x; }
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll getinv(ll x){ return ksm(x,mod-2); }
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 200005
int n,A,B; ll ans;
struct node{ int x,vx,vy; }a[N];
map<ll,int> Mp; map<pii,int> Mp2;
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read(),A=read(),B=read();
	rep (i,1,n){
		a[i].x=read(),a[i].vx=read(),a[i].vy=read();
		ll tmp=(ll)a[i].vx*A-a[i].vy; ans+=Mp[tmp];
		Mp[tmp]++;
		ans-=Mp2[pii((int)a[i].vx,(int)a[i].vy)];
		Mp2[pii((int)a[i].vx,(int)a[i].vy)]++;
	}
	ans*=2ll; cout<<ans<<endl;
	return 0;
}
// sample data:
/*
3 1 1
1 -1 -1
2 1 1
4 -1 -1
*/

// rest:
/*

*/


#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
template<typename T> void cmin(T &x,T y){ x=y<x?y:x; }
template<typename T> void cmax(T &x,T y){ x=y>x?y:x; }
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll getinv(ll x){ return ksm(x,mod-2); }
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 200005
int n,A,B; ll ans;
struct node{
	ld x,y,vx,vy;
	bool operator < (const node &t) const{ return (t.vx-vx)/(x-t.x)<(t.vy-vy)/(y-t.y); }
	bool operator == (const node &t) const{ return fabs((t.vx-vx)/(x-t.x)-(t.vy-vy)/(y-t.y))<eps; }
}a[N];
map<int,int> Mp; map<pii,int> Mp2;
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read(),A=read(),B=read();
	//node x=(node){1,1,-1,-1},y=(node){2,2,1,1};
	//if (x==y) cerr<<"!";
	//cerr<<Mp[(node){2,2,1,1}]<<endl;
	rep (i,1,n){
		int x=read(),vx=read(),vy=read();
		a[i].x=(ld)x; a[i].y=(ld)1.*A*x+B;
		a[i].vx=(ld)vx; a[i].vy=(ld)vy;
	}
	sort(a+1,a+1+n);
	for (int i=1; i<=n; ){
		int st=i,ed=i;
		while (ed<n && a[ed+1]==a[i]) ed++;
		ans+=(ll)(ed-st+1)*(ed-st)/2;// cerr<<ans<<endl;
		Mp.clear();
		rep (j,st,ed){
			ans-=Mp[(int)a[j].vx]; Mp[(int)a[j].vx]++;
			//cerr<<((int)a[j].vx)<<endl;
			//cerr<<Mp[(int)a[j].x]<<'\n';
		}
		// cerr<<ans<<endl;
		Mp.clear();
		rep (j,st,ed){ ans-=Mp[(int)a[j].vy]; Mp[(int)a[j].vy]++; }
		Mp2.clear();
		rep (j,st,ed){ ans+=Mp2[pii((int)a[j].vx,(int)a[j].vy)]; Mp2[pii((int)a[j].vx,(int)a[j].vy)]++; }
		i=ed+1;
	}
	ans*=2ll;
	cout<<ans<<endl;
	return 0;
}
// sample data:
/*

*/

// rest:
/*

*/


#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
template<typename T> void cmin(T &x,T y){ x=y<x?y:x; }
template<typename T> void cmax(T &x,T y){ x=y>x?y:x; }
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll getinv(ll x){ return ksm(x,mod-2); }
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 200005
int n,A,B; ll ans;
struct node{
	ld x,y,vx,vy;
	bool operator < (const node &t) const{ return (t.vx-vx)/(x-t.x)<(t.vy-vy)/(y-t.y); }
	bool operator == (const node &t) const{ return (t.vx-vx)/(x-t.x)==(t.vy-vy)/(y-t.y); }
}a[N];
map<int,int> Mp; map<pii,int> Mp2;
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read(),A=read(),B=read();
	rep (i,1,n){
		int x=read(),vx=read(),vy=read();
		a[i].x=(ld)x; a[i].y=(ld)A*x+(ld)B;
		a[i].vx=(ld)vx; a[i].vy=(ld)vy;
	}
	sort(a+1,a+1+n);
	for (int i=1; i<=n; ){
		int st=i,ed=i;
		while (ed<n && a[ed+1]==a[i]) ed++;
		ans+=(ll)(ed-st+1)*(ed-st)/2;
		Mp.clear();
		rep (j,st,ed){ ans-=Mp[(int)a[j].vx]; Mp[(int)a[j].vx]++; }
		Mp.clear();
		rep (j,st,ed){ ans-=Mp[(int)a[j].vy]; Mp[(int)a[j].vy]++; }
		Mp2.clear();
		rep (j,st,ed){ ans+=Mp2[pii((int)a[j].vx,(int)a[j].vy)]; Mp2[pii((int)a[j].vx,(int)a[j].vy)]++; }
		i=ed+1;
	}
	ans*=2ll; cout<<ans<<endl;
	return 0;
}
// sample data:
/*
3 1 1
1 -1 -1
2 1 1
4 -1 -1
*/

// rest:
/*

*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,a,b;
    bool f[100005],flag;
    cin>>t;
    while (t--)
    {
        memset(f,0,sizeof(f));
        cin>>a>>b;
        if (a>b)swap(a,b);
        for (int i=0; i<=100000; i+=a)
            f[i]=1;
        for (int i=0; i<=100000-b; i++)
            if (f[i])
                f[i+b]=1;
        flag=true;
        for (int i=90000; i<=100000; i++)
            if (!f[i])
            {
                flag=false;
                break;
            }
        if (flag)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,a,b;
    cin>>t;
    while (t--)
    {
        cin>>a>>b;
        if(__gcd(a,b)==1)cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,a,b,i,c;
    queue<ll>q;
    cin>>t;
    while (t--)
    {
        cin>>a>>b;
        if (a>b)swap(a,b);
        c=0;
        if (a==1)cout<<"Finite"<<endl;
        else
        {
            q.push(1);
            while (!q.empty()&&c++<=100000)
            {
                i=q.front();
                q.pop();
                if ((i+a)%b!=0)q.push(i+a);
                if ((i+b)%a!=0)q.push(i+b);
            }
            if (q.empty())cout<<"Finite"<<endl;
            else cout<<"Infinite"<<endl;
            while (!q.empty())q.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,a,b,i,c;
    queue<ll>q;
    cin>>t;
    while (t--)
    {
        cin>>a>>b;
        if (a>b)swap(a,b);
        c=0;
        if (a==1)cout<<"Finite"<<endl;
        else
        {
            for (i=1; i<a; ++i)
                q.push(i);
            while (!q.empty()&&c++<=100000)
            {
                i=q.front();
                q.pop();
                if ((i+a)%b!=0)q.push(i+a);
                if ((i+b)%a!=0)q.push(i+b);
            }
            if (q.empty())cout<<"Finite"<<endl;
            else cout<<"Infinite"<<endl;
            while (!q.empty())q.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,a,b,i,c;
    queue<ll>q;
    cin>>t;
    while (t--)
    {
        cin>>a>>b;
        if (a>b)swap(a,b);
        c=0;
        if (a==1)cout<<"Finite"<<endl;
        else
        {
            for (i=1; i<a; ++i)
                q.push(i);
            while (!q.empty()&&c++<=1000000)
            {
                i=q.front();
                q.pop();
                if ((i+a)%b!=0)q.push(i+a);
                if ((i+b)%a!=0)q.push(i+b);
            }
            if (q.empty())cout<<"Finite"<<endl;
            else cout<<"Infinite"<<endl;
            while (!q.empty())q.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        if(a ==b || (a !=1 && b !=1 && a <b)){
            cout <<"Infinite\n";
        }
        else{
            cout <<"Finite\n";
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        if((a % b ==0 || b % a ==0 )&& (a !=1 && b !=1 )){
            cout <<"Infinite\n";
        }
        else{
            cout <<"Finite\n";
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        int f =__gcd(a,b);
        if(f !=1){
            cout <<"Infinite\n";
        }
        else{
            cout<<"Finite\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        if(a ==b || (a !=1 && b !=1)){
            cout <<"Infinite\n";
        }
        else{
            cout <<"Finite\n";
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        set<int>st;
        int m =max(a,b);
        map<int , int > mp;
        for(int i =1 ; i<=m ; i++){
            if(i >=a){
                mp[i] =1;
                mp[i -a] =1;

            }
            if(i >=b){
                mp[i] =1;
                mp[i -b] =1;
            }
        }
        bool f =0;
        for(int i =0 ; i<=m ; i++){
            if(mp[i] ==0){
                f =1;
                break;
            }
        }
        if(f){
            cout <<"Infinite\n";
        }
        else{
            cout<<"Finite\n";
        }
        mp.clear();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        if(a % b ==0 || b % a ==0){
            cout <<"Infinite\n";
        }
        else{
            cout <<"Finite\n";
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >>t;
    while(t--){
        int a , b;
        cin >>a >>b;
        int f =__gcd(a,b) << endl;
        if(f !=1){
            cout <<"Infinite\n";
        }
        else{
            cout<<"Finite\n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,x,y;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        x=(a>b)?a:b;
        y=a+b-x;
        if(y*2<=x)cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,x,y;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        x=(a>b)?a:b;
        y=a+b-x;

        if(x-y==0)cout<<"Infinite"<<endl;
        else if(x%(x-y)==0 && y%(x-y)==0)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,x,y;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        x=(a>b)?a:b;
        y=a+b-x;

        if(x-y==0)cout<<"Infinite"<<endl;
        else if(x%(x-y)==0 || y%(x-y)==0)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,i,a,b,x;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        int c=0;
        int ar[10000]={0};
        x=(a>b)?a:b;
        for(i=0;i<=x;i++)
        {
            if(i==0){ar[i]=1; c++;}
            else if(ar[i-a]==1){ar[i]=1; c++;}
            else if(ar[i-b]==1){ar[i]=1; c++;}
            //cout<<ar[i]<<" ";
        }
        //cout<<endl;
        if(c<=3)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;
    }
    return 0;
}


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

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        cout<<a<<" "<<b<<endl;
        swap(a, b);
    }
    cout<<a<<endl;
    return a;
}

int main()
{
    int t;
    for (cin >> t; t--;)

    {
        int a, b;
        cin >> a >> b;

        if (gcd(a, b) == 1)
            cout << "Finite" << '\n';
        else
            cout << "Infinite" << '\n';
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,i,a,b,x;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        int c=0;
        int ar[10000]={0};
        x=(a>b)?a:b;
        for(i=0;i<=x;i++)
        {
            if(i==0){ar[i]=1; c++;}
            else if(ar[i-a]==1){ar[i]=1; c++;}
            else if(ar[i-b]==1){ar[i]=1; c++;}
        }
        if(c<=3)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,x,y,i;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        int ar[10000]={0};
        int c=0;
        x=(a>b)?a:b;
        x++;
        for(i=0;i<x;i++)
        {
            if(i==0){ar[i]=1; c++;}
            else if(ar[i-a]==1){ar[i]=1; c++;}
            else if(ar[i-b]==1){ar[i]=1; c++;}
            //cout<<ar[i]<<" ";
        }
        //cout<<endl;

        y=x-c;
        //cout<<c<<" "<<y<<endl;
        if(c<y)cout<<"Infinite"<<endl;
        else cout<<"Finite"<<endl;

    }
    return 0;
}


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

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        //cout<<a<<" "<<b<<endl;
        swap(a, b);
    }
    //cout<<a<<endl;
    return a;
}

int main()
{
    int t;
    for (cin >> t; t--;)

    {
        int a, b;
        cin >> a >> b;

        if (gcd(a, b) == 1)
            cout << "Finite" << '\n';
        else
            cout << "Infinite" << '\n';
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0, c = 0;
		cin >> a >> b;
		vector<bool>v(1e4 + 1);
		v[0] = 1;
		for (int i = 0; i <= 1e4; i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			else if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
			else
				c++;
		}
		if (cnt > c)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int OO = 0x3f3f3f3f, N = 3e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll gcd(ll a, ll b) {
	return b == 0 ? abs(a) : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll nCr(ll n, ll r){
	ll ans = 1, div = 1;
	for (ll i = r + 1; i <= n; i++){
		ans = ans * i;
		ans /= div;
		div++;
	}
	return ans;
}
ll poow(ll x, ll k, ll mod){
	ll ret = 1;
	while (k){
		if (k & 1) ret = (ret*x) % mod;
		k >>= 1; x = (x*x) % mod;
	}
	return ret;
}
int main()
{
	K_K();
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        cout<<gcd(a,b)<<endl;
    }

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		ll a, b;
		cin >> a >> b;
		ll mx = max(a, b);
		ll mn = min(a, b);
		if (mx==1||mn==1||mx%mn==1)
			cout << "Finite\n";
		else
			cout << "Infinite\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0, c = 0;
		cin >> a >> b;
		vector<bool>v(a+b+1);
		v[0] = 1;
		for (int i = 0; i <=(a+b); i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
			else
				c++;
		}
		if (cnt > c)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0;
		cin >> a >> b;
		vector<bool>v(1e4 + 1);
		v[0] = 1;
		for (int i = 0; i <= 1e4; i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			else if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
		}
		if (cnt >= 1000)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0, c = 0;
		cin >> a >> b;
		vector<bool>v(1e4 + 1);
		v[0] = 1;
		for (int i = 0; i <= 1e4; i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			else if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
			else
				c++;
		}
		if (cnt >= c)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int OO = 0x3f3f3f3f, N = 3e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll gcd(ll a, ll b) {
	return b == 0 ? abs(a) : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll nCr(ll n, ll r){
	ll ans = 1, div = 1;
	for (ll i = r + 1; i <= n; i++){
		ans = ans * i;
		ans /= div;
		div++;
	}
	return ans;
}
ll poow(ll x, ll k, ll mod){
	ll ret = 1;
	while (k){
		if (k & 1) ret = (ret*x) % mod;
		k >>= 1; x = (x*x) % mod;
	}
	return ret;
}
int main()
{
	K_K();
    int t;
    cin>>t;
    while(t--){
        int a,b,c;
        cin>>a>>b;
        c=gcd(a,b);
        if(c==1)
            cout<<"Infinite\n";
        else
            cout<<"Finite\n";
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0, c = 0;
		cin >> a >> b;
		vector<bool>v(a+b+1);
		v[0] = 1;
		for (int i = 0; i <=(a+b); i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
			else
				c++;
		}
		if (cnt >= c)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int OO = 0x3f3f3f3f, N = 3e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll gcd(ll a, ll b) {
	return b == 0 ? abs(a) : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll nCr(ll n, ll r){
	ll ans = 1, div = 1;
	for (ll i = r + 1; i <= n; i++){
		ans = ans * i;
		ans /= div;
		div++;
	}
	return ans;
}
ll poow(ll x, ll k, ll mod){
	ll ret = 1;
	while (k){
		if (k & 1) ret = (ret*x) % mod;
		k >>= 1; x = (x*x) % mod;
	}
	return ret;
}
int main()
{
	K_K();
    int t;
    cin>>t;
    while(t--){
        int a,b,c;
        cin>>a>>b;
        c=gcd(a,b);
        if(c==1)
            cout<<"Finite\n";
        else
            cout<<"Infinite\n";
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0;
		cin >> a >> b;
		vector<bool>v(1e4 + 1);
		v[0] = 1;
		for (int i = 0; i <= 1e4; i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			else if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
		}
		if (cnt >= 100)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define ss cout<<endl;system("pause");
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//r.erase(remove(all(r), '&'), r.end());
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
ll OO = (oo*oo);
void K_K()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
	K_K();
	int t;
	cin >> t;
	while (t--){
		int a, b, cnt = 0;
		cin >> a >> b;
		vector<bool>v(1e4+1);
		v[0] = 1;
		for (int i = 0; i <= 1e4; i++){
			if (i >= a && (i - a) >= 0 && (v[i - a]))
				v[i] = 1;
			else if (i >= b && (i - b) >= 0 && (v[i - b]))
				v[i] = 1;
			if (!v[i])
				cnt++;
		}
		if (cnt >= 1e2)
			cout << "Infinite\n";
		else
			cout << "Finite\n";

	}
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(a==1||b==1){
    cout<<"Finite"<<E;
    continue;
  }
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  for(int i=1;i<=max(a,b)+100;i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';cb++;
        }
        else {
            cw++;
        }
     //  cout<<i<<' '<<m[i]<<E;
  }
 //cout<<cw<<' '<<cb<<E;
  if(cw>cb)cout<<"Finite"<<E;
  else cout<<"Infinite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(a==1||b==1){
    cout<<"Finite"<<E;
    continue;
  }
  if(a==b){
    cout<<"Infinite"<<E;
    continue;
  }
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  cw+=3;
  for(int i=1;i<=max(a,b);i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';
            cb+=3;
        }
        else {
            cw+=3;
             m[i+a]='W';
        }
    cerr<<i<<' '<<m[i]<<E;
  }
cerr<<cw<<' '<<cb<<E;
  if(cb>cw)cout<<"Infinite"<<E;
  else cout<<"Finite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(gcd(a,b)==1)cout<<"Finite"<<E;
  else cout<<"Infinite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(a==1||b==1){
    cout<<"Finite"<<E;
    continue;
  }
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  for(int i=1;i<=max(a,b)+100;i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';cb++;
        }
        else {
            cw++;
        }
    cerr<<i<<' '<<m[i]<<E;
  }
cerr<<cw<<' '<<cb<<E;
  if(cb>cw)cout<<"Infinite"<<E;
  else cout<<"Finite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(a==1||b==1){
    cout<<"Finite"<<E;
    continue;
  }
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  for(int i=1;i<=max(a,b);i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';cb++;
            m[i+a]='B';
            cb++;
            if(m.find(i+b)==m.end()){m[i+b]='B';cb++;}
        }
        else {
            cw++;
             m[i+a]='W';
            cw++;
            if(m.find(i+b)==m.end()){m[i+b]='W';cw++;}
        }
    cerr<<i<<' '<<m[i]<<E;
  }
cerr<<cw<<' '<<cb<<E;
  if(cb>cw)cout<<"Infinite"<<E;
  else cout<<"Finite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  if(a==1||b==1){
    cout<<"Finite"<<E;
    continue;
  }
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  for(int i=1;i<10001;i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';
        }
        else {
            if(m[i-1]=='W')
            cw++;
            else cb++;
        }
      // cout<<i<<' '<<m[i]<<E;
  }
 //cout<<cw<<' '<<cb<<E;
  if(cw>cb)cout<<"Finite"<<E;
  else cout<<"Infinite"<<E;
  }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define  E endl
#define loop(a,n) for(int i=a;i<n;i++)
#define loop1(a,n) for(int j=a;j<n;j++)
#define loop_r(a,n) for(int i=n-1;i>=a;i--)
#define  loop_it(m,it) for(it=m.begin();it!=m.end();it++)
int main()
{
  int t,a,b;
  cin>>t;
  loop(0,t){
  cin>>a>>b;
  map<int,char>m;
  int cw=0,cb=0;
  m[0]='W';
  for(int i=1;i<10001;i++){
        if(i>=a){
            if(m[i-a]=='W'){m[i]='W';}
        }
       if(i>=b){
            if(m[i-b]=='W')m[i]='W';
        }
        if(m.find(i)==m.end()){
            m[i]='B';cb++;
        }
        else {if(i!=a&&i!=b)cw++;}
       // cout<<i<<' '<<m[i]<<E;
  }
 // cout<<cw<<' '<<cb<<E;
  if(cw-cb>1000)cout<<"Finite"<<E;
  else cout<<"Infinite"<<E;
  }
    return 0;
}


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

int main()
{
    int t=1;
    cin>>t;
    while(t--){
        int n,a;
        cin>>n>>a;
        if(_gcd(n,a)==1){
            cout<<"Finite"<<endl;
        }
        else{
            cout<<"Infinite"<<endl;
        }

    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a==1 || b==1){
            cout<<"Finite"<<endl;
        }
        else if(b<a){
            cout<<"Finite"<<endl;
        }
        else{
            cout<<"Infinite"<<endl;
        }

    }
    return 0;

}


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

int main()
{
    int t=1;
    cin>>t;
    while(t--){
        int n,a;
        cin>>n>>a;
        if(__gcd(n,a)==1){
            cout<<"Finite"<<endl;
        }
        else{
            cout<<"Infinite"<<endl;
        }

    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a==1 || b==1){
            cout<<"Finite"<<endl;
        }
        else if(abs(a-b)>3){
            cout<<"Finite"<<endl;
        }
        else{
            cout<<"Infinite"<<endl;
        }

    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin >> x;
    while(x--){
        int a  , b ;
        cin >> a >> b ;
         if((__gcd(a, b))!=1)
            cout << "Infinite" << endl;
         else
            cout << "Finite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isprime(int a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0)
            return false;
    }
    return true;
}
bool isprime2(int b){
    for(int i=2;i*i<=b;i++){
        if(b%i==0)
            return false;
    }
    return true;
}
int main()
{
    int x;
    cin >> x;
    while(x--){
        int a  , b ;
        cin >> a >> b ;
        if(isprime(a)||isprime2(b)&&a!=b)
            cout << "Finite" << endl;
        else {
            for(int i=2;i<=min(a,b);i++){
                if(a%i==0&&b%i==0)
                {cout << "Infinte" << endl;break;}
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isprime(int a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0)
            return false;
    }
    return true;
}
bool isprime2(int b){
    for(int i=2;i*i<=b;i++){
        if(b%i==0)
            return false;
    }
    return true;
}
int main()
{
    int x;
    cin >> x;
    while(x--){
        int a  , b ;
        cin >> a >> b ;
        if(isprime(a)||isprime2(b)&&a!=b)
            cout << "Finite" << endl;
        else {
            for(int i=2;i<=min(a,b);i++){
                if(a%i==0&&b%i==0)
                {cout << "Infinite" << endl;break;}
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin >> x;
    while(x--){
        bool f = false;
        int a  , b ;
        cin >> a >> b ;
        for(int i=2;i<=min(a,b);i++){
            if(a%i==0&&b%i==0)
                {cout << "Infinite" << endl;f=true;break;}
        }
        if(!f)
            cout << "Finite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool isprime(int a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0)
            return false;
    }
    return true;
}
int main()
{
    int x;
    cin >> x;
    while(x--){
        int a  , b ;
        cin >> a >> b ;
        if(isprime(a)||isprime(b)&&a!=b)
            cout << "Finite" << endl;
        else {
            for(int i=2;i<=min(a,b);i++){
                if(a%i==0&&b%i==0)
                {cout << "Infinite" << endl;break;}
            }
        }
    }
    return 0;
}


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

int main()
{
   int t;
   cin>>t;
   while(t--){
       int a,b;
       cin>>a>>b;
      int k = __gcd(a,b);
      if(k<2){
         cout<<"Finite"<<endl;
      }
      else{
          cout<<"Infinite"<<endl;
      }
   }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
      int a,b;
      cin>>a>>b;
    int n =  max(a,b);
    if((a%2==0 && b%2==0) || (a%3==0 && b%3==0)){
        cout<<"Infinite"<<endl;
    }
    else{
        cout<<"Finite"<<endl;
    }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
      int a,b;
      cin>>a>>b;
     int n = __gcd(a,b);
     if(n>2){
        cout<<"Infinte"<<endl;
     }
     else{
         cout<<"Finite"<<endl;
     }
}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
      int a,b;
      cin>>a>>b;
     int n = __gcd(a,b);
     if(n>2){
        cout<<"Infinite"<<endl;
     }
     else{
         cout<<"Finite"<<endl;
     }
}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
      int a,b;
      cin>>a>>b;
     int n = __gcd(a,b);
     if(n>2){
        cout<<"infinte";
     }
     else{
         cout<<"finite";
     }
}
    return 0;
}


//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<int>

#define ses   "\n"
#define whp   " "

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
            int a, b,q=0;cin>>a>>b;
            if(a>b)swap(a,b);
            if(a==1 || b==1)
                cout<<"Finite"<<ses;
            else if(a%2==0 && b%2==0)
                cout<<"Infinite"<<ses;
            else if(b%a==0)
                cout<<"Infinite"<<ses;
            else
            {
                if(a%3==0 && b%3==0)
                    cout<<"Infinite"<<ses;
                else
                {
                    for(int i=5;i*i<=a;i=i+8)
                    {
                        if(a%i==0 && b%i==0){
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else if(a%(i+2)==0 && b%(i+2)==0)
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else if(a%(i+4)==0 && b%(i+4)==0)
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else if(a%(i+6)==0 && b%(i+6)==0)
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                    }
                    if(q==0)cout<<"Finite"<<ses;
                }
            }
    }

    return 0;
}


//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<int>

#define ses   "\n"
#define whp   " "

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
            int a, b,q=0;cin>>a>>b;
            if(a>b)swap(a,b);
            if(a==1 || b==1)
                cout<<"Finite"<<ses;
            else if(a%2==0 && b%2==0)
                cout<<"Infinite"<<ses;
            else if(b%a==0)
                cout<<"Infinite"<<ses;
            else
            {
                if(a%3==0 && b%3==0)
                    cout<<"Infinite"<<ses;
                else
                {
                    for(int i=5;i*i<=a;i=i+8)
                    {
                        if(a%i==0 && b%i==0){
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else if(a%(i+2)==0 && b%(i+2)==0)
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else if(a%(i+4)==0 && b%(i+4)==0)
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                        else
                        {
                            cout<<"Infinite"<<ses;q=1;
                            break;
                        }
                    }
                    if(q==0)cout<<"Finite"<<ses;
                }
            }
    }

    return 0;
}


//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<int>

#define ses   "\n"
#define whp   " "

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
            int a, b,q=0,x=99999;cin>>a>>b;
            if(a>b)swap(a,b);
            if(a==1 || b==1)
                cout<<"Finite"<<ses;
            else if(b%a==0)
                cout<<"Infinite"<<ses;
            else
            {
                    for(int i=2;;i++)
                    {
                        if(a%i==0 && b%i==0){
                            cout<<"Infinite"<<ses;q=1;
                            break;
                       }
                     if(i>a || i>b)break;
                     }
                    if(q==0)cout<<"Finite"<<ses;
             }
    }

    return 0;
}


//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<int>

#define ses   "\n"
#define whp   " "

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
        int a, b,count =1;cin>>a>>b;
    if(a>b)swap(a,b);
    if(a==1 || b==1)
       cout<<"Finite"<<ses;
    else if(a<10)
    {
        if(a==2)
            cout<<"Finite"<<ses;
        else if(a==3)
        {
            if(b==5 || b==7 || b==8 || b==4)
                cout<<"Finite"<<ses;
            else
                cout<<"Infinite"<<ses;
        }
        else if((a==3 && b==4) || (a==2 && b==3) || (a==4 && b==5))
        cout<<"Finite"<<ses;
        else cout<<"Infinite"<<ses;
    }
    else
        cout<<"Infinite"<<ses;
    }
    return 0;
}


//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<int>

#define ses   "\n"
#define whp   " "

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
            int a, b,q=0;cin>>a>>b;
            if(a>b)swap(a,b);
            if(a==1 || b==1)
                cout<<"Finite"<<ses;
            else if(b%a==0)
                cout<<"Infinite"<<ses;
            else
            {
                    for(int i=5;;i=i+8)
                    {
                        if(a%i==0 && b%i==0){
                            cout<<"Infinite"<<ses;q=1;
                            break;
                       }
                     if(i>a || i>b)break;
                     }
                    if(q==0)cout<<"Finite"<<ses;
             }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  if(n==m)
  {
      cout<<"Infinite\n";
      return;
  }
  int maxi=max(n,m);
  int mini=min(n,m);
  int val=(maxi/mini);
  if(val+2>(maxi-(val+2)))cout<<"Finite\n";
  else cout<<"Infinite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  int maxi=max(n,m);
  int mini=min(n,m);
  int val=(maxi/mini);
  if(val+2>=(maxi+1-(val+2)))cout<<"Finite\n";
  else cout<<"Infinite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  if(__gcd(n,m)!=1)cout<<"Infinite\n";
  else cout<<"Finite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  if(n==m)
  {
      cout<<"Infinite\n";
  }
  int maxi=max(n,m);
  int mini=min(n,m);
  int val=(maxi/mini);
  if(val+2>(maxi-(val+2)))cout<<"Finite\n";
  else cout<<"Infinite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  int maxi=max(n,m);
  int mini=min(n,m);
  int val=(maxi/mini);
  if(val+2>(maxi-(val+2)))cout<<"Finite\n";
  else cout<<"Infinite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}