#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=998244353;
const ll N=300005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll fact[N+2],invf[N+2];

void calc(){
	fact[0]=1;
	for1(i,N){
		fact[i]=fact[i-1]*i%mod;
	}
	invf[N]=powmod(fact[N],mod-2);
	for(int i=N-1;i>=0;i--){
		invf[i]=invf[i+1]*(i+1)%mod;
	}
}

ll choose(int n,int r){
	if(n<r)return 0;
	return fact[n]*invf[r]%mod * invf[n-r]%mod;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif
    calc();
    int t=1;
    // cin>>t;
    while(t--){
    	int n,k;cin>>n>>k;
    	map<ll,int> m1,ml,mr;
    	forn(i,n){
    		int l,r;cin>>l>>r;
    		m1[l]++;
    		m1[r+1]--;
    		ml[l]++;

    	}
    	ll ans=0,ct=0;
    	for(auto i:m1){
    		ct+=i.se;
    		if(ct>=k){
	    		int rem=ct-ml[i.fi];
	    		(ans+=choose(ct,k)-choose(rem,k))%=mod;
	    	}
    	}
    	ans=(ans+mod)%mod;
    	cout<<ans;
    }
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double

#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>

#define pll pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vl>
#define vpll vector<pll>

#define inl(x) ll x;cin>>x
#define in(x) int x;cin>>x
#define mk(t,a,n) t*a = new t[n]
#define inp(a,n) for(int i = 0;i<n;i++)cin>>a[i]
#define sea(a,n,v) for(int i = 0;i<n;i++)a[i] = v
#define pb push_back
#define F first
#define S second
#define LEFT 2*I+1
#define RIGHT 2*I+2
#define endl "\n"
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define um unordered_map
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define test() int t;cin>>t;while(t--)
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int mod = 998244353,MAX = 1e6+5;
const ll inf = 1e18+5;
const double pi = 3.14159265358979323846;

//https://github.com/rkas123/TEMPLATE/blob/master/Template.cpp
//Template taken from here

using namespace std;
ll factorial[300005];
ll fastexp(ll a,ll b)
{
    ll ans=1;
    ll temp=a;
    while(b>0)
    {
        if(b&1)
            ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b>>=1;
    }
    return ans;
}
//                                      NCR
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll n1=factorial[n];
    ll n2=factorial[r];
    ll n3=factorial[n-r];
    n2=fastexp(n2,mod-2);
    n3=fastexp(n3,mod-2);
    return (((n1*n2)%mod)*n3)%mod;
}
int lb(vi v,int key)
{
    int s=0;
    int e=v.size()-1;
    int answer=-1;
    while(s<=e)
    {
        int mid=(s+e)/2;
        if(v[mid] > key)
        {
            e=mid-1;
        }
        else
        {
            answer=mid;
            s=mid+1;
        }
    }
    return answer;
}
int ub(vi v, int key)
{
    int answer=-1;
    int s=0;
    int e=v.size()-1;
    while(s<=e)
    {
        int mid=(s+e)/2;
        if(v[mid] < key)
        {
            s=mid+1;
        }
        else
        {
            e=mid-1;
            answer=mid;
        }
    }
    return answer;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
    factorial[0]=1ll;
    for(int i=1;i<=300004;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    in(n);inl(k);
    //set<int> pos;
    vi l;
    vi r;
    mii count;
    for(int i=0;i<n;i++)
    {
        in(a);in(b);
        //pos.insert(a);
        l.pb(a);
        r.pb(b);
        count[a]++;
    }
    ll answer=0ll;
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    for(auto it: count)
    {
        int curr=it.F;
        //cout<<curr<<endl;
        int less=lb(r,curr-1)+1;
        int more=ub(l,curr+1);
        if(more==-1)
        {
            more=0;
        }
        else
        {
            more=n-more;
        }
        ll p=n-less-more;
        ll s=count[curr];
        if(p>=k){
            answer=(answer+(ncr(p,k)-ncr(p-s,k)))%mod;
        }
        //cout<<curr<<" "<<s<<" "<<p<<" "<<answer<<endl;
    }
    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double

#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>

#define pll pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vl>
#define vpll vector<pll>

#define inl(x) ll x;cin>>x
#define in(x) int x;cin>>x
#define mk(t,a,n) t*a = new t[n]
#define inp(a,n) for(int i = 0;i<n;i++)cin>>a[i]
#define sea(a,n,v) for(int i = 0;i<n;i++)a[i] = v
#define pb push_back
#define F first
#define S second
#define LEFT 2*I+1
#define RIGHT 2*I+2
#define endl "\n"
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define um unordered_map
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define test() int t;cin>>t;while(t--)
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int mod = 998244353,MAX = 1e6+5;
const ll inf = 1e18+5;
const double pi = 3.14159265358979323846;

//https://github.com/rkas123/TEMPLATE/blob/master/Template.cpp
//Template taken from here

using namespace std;
ll factorial[300005];
ll fastexp(ll a,ll b)
{
    ll ans=1;
    ll temp=a;
    while(b>0)
    {
        if(b&1)
            ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b>>=1;
    }
    return ans;
}
//                                      NCR
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll n1=factorial[n];
    ll n2=factorial[r];
    ll n3=factorial[n-r];
    n2=fastexp(n2,mod-2);
    n3=fastexp(n3,mod-2);
    return (((n1*n2)%mod)*n3)%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
    factorial[0]=1ll;
    for(int i=1;i<=300004;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    inl(n);inl(k);
    map<ll,ll> count;
    map<ll,bool> first;
    map<ll,ll> event;
    for(int i=0;i<n;i++)
    {
        inl(a);inl(b);
        first[a]=true;
        event[a]++;
        event[b+1]--;
        count[a]++;
    }
    ll cnt=0ll;
    ll answer=0ll;
    for(auto it: event)
    {
        cnt+=(it.S);
        if(first[it.F])
        {
            ll s=count[it.F];
            answer=(answer+(ncr(cnt,k) - ncr(cnt-s,k)))%mod;

        }
    }
    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double

#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>

#define pll pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vl>
#define vpll vector<pll>

#define inl(x) ll x;cin>>x
#define in(x) int x;cin>>x
#define mk(t,a,n) t*a = new t[n]
#define inp(a,n) for(int i = 0;i<n;i++)cin>>a[i]
#define sea(a,n,v) for(int i = 0;i<n;i++)a[i] = v
#define pb push_back
#define F first
#define S second
#define LEFT 2*I+1
#define RIGHT 2*I+2
#define endl "\n"
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define um unordered_map
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define test() int t;cin>>t;while(t--)
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int mod = 998244353,MAX = 1e6+5;
const ll inf = 1e18+5;
const double pi = 3.14159265358979323846;

//https://github.com/rkas123/TEMPLATE/blob/master/Template.cpp
//Template taken from here

using namespace std;
ll factorial[300005];
ll fastexp(ll a,ll b)
{
    ll ans=1;
    ll temp=a;
    while(b>0)
    {
        if(b&1)
            ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b>>=1;
    }
    return ans;
}
//                                      NCR
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll n1=factorial[n];
    ll n2=factorial[r];
    ll n3=factorial[n-r];
    n2=fastexp(n2,mod-2);
    n3=fastexp(n3,mod-2);
    return (((n1*n2)%mod)*n3)%mod;
}
int lb(vi v,int key)
{
    int s=0;
    int e=v.size()-1;
    int answer=-1;
    while(s<=e)
    {
        int mid=(s+e)/2;
        if(v[mid] > key)
        {
            e=mid-1;
        }
        else
        {
            answer=mid;
            s=mid+1;
        }
    }
    return answer;
}
int ub(vi v, int key)
{
    int answer=-1;
    int s=0;
    int e=v.size()-1;
    while(s<=e)
    {
        int mid=(s+e)/2;
        if(v[mid] < key)
        {
            s=mid+1;
        }
        else
        {
            e=mid-1;
            answer=mid;
        }
    }
    return answer;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
    factorial[0]=1ll;
    for(int i=1;i<=300004;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    in(n);inl(k);
    set<int> pos;
    vi l;
    vi r;
    mii count;
    for(int i=0;i<n;i++)
    {
        in(a);in(b);
        pos.insert(a);
        l.pb(a);
        r.pb(b);
        count[a]++;
    }
    ll answer=0ll;
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    while(!pos.empty())
    {
        int curr=*(pos.begin());
        pos.erase(pos.begin());
        //cout<<curr<<endl;
        int less=lb(r,curr-1)+1;
        int more=ub(l,curr+1);
        if(more==-1)
        {
            more=0;
        }
        else
        {
            more=n-more;
        }
        ll p=n-less-more;
        ll s=count[curr];
        if(p>=k){
            answer=(answer+(ncr(p,k)-ncr(p-s,k)))%mod;
        }
        //cout<<curr<<" "<<s<<" "<<p<<" "<<answer<<endl;
    }
    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double

#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>

#define pll pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vl>
#define vpll vector<pll>

#define inl(x) ll x;cin>>x
#define in(x) int x;cin>>x
#define mk(t,a,n) t*a = new t[n]
#define inp(a,n) for(int i = 0;i<n;i++)cin>>a[i]
#define sea(a,n,v) for(int i = 0;i<n;i++)a[i] = v
#define pb push_back
#define F first
#define S second
#define LEFT 2*I+1
#define RIGHT 2*I+2
#define endl "\n"
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define um unordered_map
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define test() int t;cin>>t;while(t--)
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const ll mod = 998244353,MAX = 1e6+5;
const ll inf = 1e18+5;
const double pi = 3.14159265358979323846;

//https://github.com/rkas123/TEMPLATE/blob/master/Template.cpp
//Template taken from here

using namespace std;
ll factorial[300005];
ll invfact[300005];
ll fastexp(ll a,ll b)
{
    ll ans=1ll;
    ll temp=a;
    while(b>0)
    {
        if(b&1)
            ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b>>=1;
    }
    return ans;
}
//                                      NCR
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0ll;
    ll num=factorial[n];
    num*=invfact[r];
    num%=mod;
    num*=invfact[n-r];
    num%=mod;
    return num;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
    factorial[0]=1ll;
    for(ll i=1ll;i<=300004;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    invfact[300004]=fastexp(factorial[300004],mod-2);
    for(int i=300003;i>=0;i--)
    {
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]%=mod;
    }
//cout<<factorial[5]<<endl;
    inl(n);inl(k);
    map<ll,ll> count;
    map<ll,ll> event;
    for(int i=0;i<n;i++)
    {
        inl(a);inl(b);
        event[a]++;
        event[b+1]--;
        count[a]++;
    }
    ll cnt=0ll;
    ll answer=0ll;
    ll prev;
    for(auto it: event)
    {
        prev=answer;
        cnt+=(it.S);
        ll s=count[it.F];
        if(cnt>=k){
            ll rem=cnt-s;
            answer=(answer+(ncr(cnt,k)-ncr(rem,k))%mod)%mod;
        }
    }
    answer=(answer+mod)%mod;
    cout<<answer<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<long long int , long long int> tup;

long long int maxN = 300009;
long long int m = 998244353;

long long int power(long long int x,long long int y,long long int p)
    {
        long long int res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    long long int n , k;
    long long int count = 0, total = 0;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(long long int i = 0; i < n; i++)
    {
        long long int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <long long int> fac(n + 1, 1);
    vector <long long int> modinv(n + 1 , 1);
    vector <long long int> f(n + 1 , 1);

    // Calculate factorial % m
    for(long long int i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(long long int i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m) % m;

    // Calculate nCr % m
    for(long long int i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(long long int i = 0; i < 2*n; i++)
    {
        sort[i] = heap.top();
        heap.pop();
    }

    for(long long int i = 0; i < 2*n; i++)
    {
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1]%m;
                total = total % m;
            }

            count -= 1;
        }
    }

    cout << total;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[i] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009
ll m = 998244353

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[w] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
    {
        sort[i] = heap.top();
        heap.pop();
    }

    for(ll i = 0; i < 2*n; i++)
    {
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }
    }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<long long int , long long int> tup;

long long int maxN = 300009;
long long int m = 998244353;

long long int power(long long int x,long long int y,long long int p)
    {
        long long int res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    long long int n , k;
    long long int count = 0, total = 0;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    // cout << "Here 1";
    for(long long int i = 0; i < n; i++)
    {
        long long int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(r , 1));

    }

    // cout << "Here 2";

    vector <long long int> fac(maxN + 1, 1);
    vector <long long int> modinv(maxN + 1 , 1);
    vector <long long int> f(maxN + 1 , 1);

    // Calculate factorial % m
    for(long long int i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(long long int i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m) % m;

    // Calculate nCr % m
    for(long long int i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    // cout << "Here 3";

    vector<tup> sort(2*n);
    for(long long int i = 0; i < 2*n; i++)
    {
        sort[i] = heap.top();
        heap.pop();
    }

    // cout << "Here 4";

    for(long long int i = 0; i < 2*n; i++)
    {
        if (sort[i].second == 0)
        {
            count += 1;
        }

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1]%m;
                total = total % m;
            }

            count -= 1;
        }
    }

    cout << total << "\n";

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    int n , k;
    long long int count = 0, total = 0;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(long long int i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(long long int i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m) % m;

    // Calculate nCr % m
    for(long long int i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(long long int i = 0; i < 2*n; i++)
    {
        sort[i] = heap.top();
        heap.pop();
    }

    for(long long int i = 0; i < 2*n; i++)
    {
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }
    }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    int n , k;
    long long int count = 0, total = 0;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        long long int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(long long int i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(long long int i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m) % m;

    // Calculate nCr % m
    for(long long int i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(long long int i = 0; i < 2*n; i++)
    {
        sort[i] = heap.top();
        heap.pop();
    }

    for(long long int i = 0; i < 2*n; i++)
    {
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1]%m;
                total = total % m;
            }

            count -= 1;
        }
    }

    cout << total;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
#define maxN 300009
#define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    ll power(ll x,ll y,ll p){
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[w] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[w] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        cin >> l >> r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[w] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

    cout << total % m;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long int
// #define maxN 300009
// #define m 998244353
using namespace std;
typedef pair<ll , ll> tup;

ll maxN = 300009;
ll m = 998244353;

int main()
{
    int n , k;
    ll count , total;
    cin >> n >> k;

    priority_queue< tup, vector< tup > , greater< tup > > heap;

    for(int i = 0; i < n; i++)
    {
        int l , r;
        heap.emplace(make_pair(l , 0));
        heap.emplace(make_pair(l , 0));

    }

    ll power(ll x,ll y,ll p)
    {
        ll res = 1;

        x = x % p;
        while (y > 0)
        {
            if ( y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    vector <int> fac(n + 1, 1);
    vector <int> modinv(n + 1 , 1);
    vector <int> f(n + 1 , 1);

    // Calculate factorial % m
    for(ll i = 1; i < maxN; i++ )
        fac[i] = (fac[i - 1] * i) % m;

    // Calculate inverse % m
    for(ll i = 0; i < maxN; i++)
        modinv[i] = power(fac[i] , m - 2 , m);

    // Calculate nCr % m
    for(ll i = k - 1; i < maxN; i++)
        f[i] =  (((fac[i] * modinv[k - 1]) % m) * modinv[i - k + 1]) % m;

    vector<tup> sort(2*n);
    for(ll i = 0; i < 2*n; i++)
        sort[w] = heap.top();
        heap.pop();

    for(ll i = 0; i < 2*n; i++)
        if (sort[i].second == 0)
            count += 1;

        if (sort[i].second == 1)
        {

            if (count >= k)
            {
                total += f[count - 1];
                total = total % m;
            }

            count -= 1;
        }

    cout << total % m;

    return 0;
}


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

#pragma GCC optimize(3)
//#define int ll
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const ll mo = 998244353;
typedef pair<int, int> pii;

int n,k;
pii a[2*maxn];
ll fact[maxn],infact[maxn];

ll pow(ll aa,ll b,ll p){
    int res=1;
    while (b){
        if (b&1) res=res*aa%p;
        b>>=1;
        aa=aa*aa%p;
    }
    return res;
}

void init(){
    fact[0]=infact[0]=1;
    for (int i = 1; i <=n; ++i) {
        fact[i]=fact[i-1]*i%mo;
        infact[i]=pow(fact[i],mo-2,mo);
    }
}

void solve() {
    cin>>n>>k;
    init();
    for (int i = 1; i <=n; ++i) {
        int l,r;
        cin>>l>>r;
        a[i].first=l,a[i].second=-1;
        a[i+n].first=r,a[i+n].second=1;
    }
    sort(a+1,a+2*n+1);
    int sum=0,cnt=0;
    for (int i = 1; i <=2*n; ++i) {
        if (a[i].second==-1){
            if (cnt>=k-1) sum=(sum+fact[cnt]*infact[k-1]%mo*infact[cnt-k+1]%mo)%mo;
            cnt++;
        }else cnt--;
    }
    cout<<sum<<"\n";
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


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

#pragma GCC optimize(2)
//#define int ll
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const ll mo = 998244353;
typedef pair<int, int> pii;

int n,k;
pii a[2*maxn];
ll fact[maxn],infact[maxn];

ll pow(ll aa,ll b,ll p){
    int res=1;
    while (b){
        if (b&1) res=res*aa%p;
        b>>=1;
        aa=aa*aa%p;
    }
    return res;
}

void init(){
    fact[0]=infact[0]=1;
    for (int i = 1; i <=n; ++i) {
        fact[i]=fact[i-1]*i%mo;
        infact[i]=pow(fact[i],mo-2,mo);
    }
}

void solve() {
    cin>>n>>k;
    init();
    for (int i = 1; i <=n; ++i) {
        int l,r;
        cin>>l>>r;
        a[i].first=l,a[i].second=-1;
        a[i+n].first=r,a[i+n].second=1;
    }
    sort(a+1,a+2*n+1);
    int sum=0,cnt=0;
    for (int i = 1; i <=2*n; ++i) {
        if (a[i].second==-1){
            if (cnt>=k-1) sum=(sum+fact[cnt]*infact[k-1]%mo*infact[cnt-k+1]%mo)%mo;
            cnt++;
        }else cnt--;
    }
    cout<<sum<<"\n";
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 300010;
const ll mod = 998244353;
pii a[2 * N];
int n, k;

ll qmi(ll a, ll b, ll p) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % p;
        b >>= 1;
        a = a * a % p;
    }
    return res;
}

ll fact[N], infact[N];

void init(int n) {
    fact[0] = infact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] = qmi(fact[i], mod - 2, mod);
    }
}

int main() {
    IO;
    int T = 1;
    //cin>>T;
    while (T--) {
        cin >> n >> k;
        init(n);
        for (int i = 1; i <= n; i++) {
            int l, r;
            cin >> l >> r;
            a[i].first = l, a[i].second = -1;//左端点
            a[i + n].first = r, a[i + n].second = 1;//右端点
        }
        sort(a + 1, a + 1 + 2 * n);
        ll res = 0;
        ll cnt = 0;
        for (int i = 1; i <= 2 * n; i++) {
            int id = a[i].second;
            if (id == -1) {
                if (cnt >= k - 1)
                    res = (res + fact[cnt] * infact[k - 1] % mod * infact[cnt - k + 1] % mod) % mod;
                cnt++;
            } else cnt--;
        }
        cout << res << '\n';
    }
    return 0;
}


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

//#pragma GCC optimize(2)
//#define int ll
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const ll mo = 998244353;
typedef pair<int, int> pii;

int n,k;
pii a[2*maxn];
ll fact[maxn],infact[maxn];

ll pow(ll aa,ll b,ll p){
    int res=1;
    while (b){
        if (b&1) res=res*aa%p;
        b>>=1;
        aa=aa*aa%p;
    }
    return res;
}

void init(){
    fact[0]=infact[0]=1;
    for (int i = 1; i <=n; ++i) {
        fact[i]=fact[i-1]*i%mo;
        infact[i]=pow(fact[i],mo-2,mo);
    }
}

void solve() {
    cin>>n>>k;
    init();
    for (int i = 1; i <=n; ++i) {
        int l,r;
        cin>>l>>r;
        a[i].first=l,a[i].second=-1;
        a[i+n].first=r,a[i+n].second=1;
    }
    sort(a+1,a+2*n+1);
    int sum=0,cnt=0;
    for (int i = 1; i <=2*n; ++i) {
        int id=a[i].second;
        if (id==-1){
            if (cnt>=k-1)
                sum=(sum+fact[cnt]*infact[k-1]%mo*infact[cnt-k+1]%mo)%mo;
            cnt++;
        }else cnt--;
    }
    cout<<sum<<"\n";
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


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

//#pragma GCC optimize(2)
//#define int ll
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const ll mo = 998244353;
typedef pair<int, int> pii;

int n,k;
pii a[2*maxn];
ll fact[maxn],infact[maxn];

ll pow(ll aa,ll b,ll p){
    int res=1;
    while (b){
        if (b&1) res=res*aa%p;
        b>>=1;
        aa=aa*aa%p;
    }
    return res;
}

void init(){
    fact[0]=infact[0]=1;
    for (int i = 1; i <=n; ++i) {
        fact[i]=fact[i-1]*i%mo;
        infact[i]=pow(fact[i],mo-2,mo);
    }
}

void solve() {
    cin>>n>>k;
    init();
    for (int i = 1; i <=n; ++i) {
        int l,r;
        cin>>l>>r;
        a[i].first=l,a[i].second=-1;
        a[i+n].first=r,a[i+n].second=1;
    }
    sort(a+1,a+2*n+1);
    int sum=0,cnt=0;
    for (int i = 1; i <=2*n; ++i) {
        if (a[i].second==-1){
            if (cnt>=k-1) sum=(sum+fact[cnt]*infact[k-1]%mo*infact[cnt-k+1]%mo)%mo;
            cnt++;
        }else cnt--;
    }
    cout<<sum<<"\n";
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back
int fact[300005];
int inv[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
		inv[i] = (inv[mod%i]*(mod-mod/i))%mod;
	}
	for(int i=2;i<=300000;++i){
		inv[i] = (inv[i-1]*inv[i])%mod;
	}
}
int ncr(int n,int r){
	return (fact[n]*((inv[n-r]*inv[r])%mod))%mod;
}

void fastscan(int &x){
	bool neg=false;
	register int c;
	x = 0;
	c=getchar();
	if(c=='-'){
		neg = true;
		c=getchar();
	}
	for(;(c>47 && c<58);c=getchar()) x = (x<<1) + (x<<3) +c -48;
	if(neg) x *=-1;
}
int n,k,l,r;
int32_t main(){
	FAST_IO;
	init();
	int n,k;
	fastscan(n);
	fastscan(k);
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		fastscan(l);
		fastscan(r);
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back

int fact[300005];
int inv[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
		inv[i] = inv[mod%i]*(mod-mod/i)%mod;
	}
	for(int i=2;i<=300000;++i){
		inv[i] = (inv[i-1]*inv[i])%mod;
	}
}
int ncr(int n,int r){
	return (fact[n]*inv[n-r]%mod*inv[r]%mod)%mod;
}

int32_t main(){
	FAST_IO;
	init();
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		int l,r;
		cin>>l>>r;
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back

int fact[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
	}
}

int p(int x,int y){
	int res=1;
	while(y){
		if(y&1){
			res = (res*x)%mod;
		}
		x = (x*x)%mod;
		y = y>>1;
	}
	return res;
}

int ncr(int n,int r){
	int ans = fact[n];
	ans = (ans*p(fact[n-r],mod-2))%mod;
	ans = (ans*p(fact[r],mod-2))%mod;
	return ans;
}

int32_t main(){
	FAST_IO;
	init();
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		int l,r;
		cin>>l>>r;
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back

int fact[300005];
int inv[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
		inv[i] = (inv[mod%i]*(mod-mod/i))%mod;
	}
	for(int i=2;i<=300000;++i){
		inv[i] = (inv[i-1]*inv[i])%mod;
	}
}
int ncr(int n,int r){
	return (fact[n]*((inv[n-r]*inv[r])%mod))%mod;
}

int32_t main(){
	FAST_IO;
	init();
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		int l,r;
		cin>>l>>r;
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back

int fact[300005];
int inv[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
		inv[i] = (inv[mod%i]*(mod-mod/i))%mod;
	}
	for(int i=2;i<=300000;++i){
		inv[i] = (inv[i-1]*inv[i])%mod;
	}
}
int ncr(int n,int r){
	return (fact[n]*inv[n-r]%mod*inv[r]%mod)%mod;
}

int32_t main(){
	FAST_IO;
	init();
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		int l,r;
		cin>>l>>r;
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define int long long
#define endl '\n'
#define pb push_back

int fact[300005];
int inv[300005];
bool compare(pair<int,int> &p1,pair<int,int>&p2){
	if(p1.first != p2.first){
		return p1.first<p2.first;
	}
	else{
		return p1.second>p2.second;
	}
}
void init(){
	fact[0] = fact[1] = 1;
	inv[0] = inv[1] = 1;
	for(int i=2;i<=300000;++i){
		fact[i] = (i*fact[i-1])%mod;
		inv[i] = (inv[mod%i]*(mod-mod/i))%mod;
	}
	for(int i=2;i<=300000;++i){
		inv[i] = (inv[i-1]*inv[i])%mod;
	}
}
int ncr(int n,int r){
	return (fact[n]*(inv[n-r]*inv[r])%mod)%mod;
}

int32_t main(){
	FAST_IO;
	init();
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i){
		int l,r;
		cin>>l>>r;
		v.pb({l,1});
		v.pb({r,0});
	}
	int ans=0;
	int curr=0;
	sort(v.begin(), v.end(),compare);
	for(int i=0;i<v.size();++i){
		if(v[i].second==1){
			if(curr>=k-1){
				ans = (ans+ncr(curr,k-1))%mod;
			}
			curr++;
		}
		else{
			curr--;
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define maxn 600013
#define maxm 213
#define eps 1e-7
#define M (ll)998244353
#define M2 (ll)1000000009
#define inf 1e18
#define pi acos(-1)

ll a[maxn], sum[maxn];
int n;
void add(int p, ll x){
    while(p <= n) sum[p] += x, p += p & -p;
}
void rad(int l, int r, ll x){
    add(l, x), add(r + 1, -x);
}
ll que(int p){
    ll res = 0;
    while(p) res += sum[p], p -= p & -p;
    return res;
}
ll fac[maxn], c[maxn];
ll ta[maxn];
set<ll> st;
map<ll, ll> mp;
int k;
ll qpm(ll a, ll b) {
	a%=M;
	ll res=1;
	while(b>0) {
		if(b&1) res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res;
}
ll C(ll a, ll b){
	if(a<b) return 0;
	ll res=fac[a];
	res=res*qpm(fac[b], M-2)%M*qpm(fac[a-b], M-2)%M;
	return res;
}
int main() {
	fac[0]=fac[1]=1;
	for(int i=2; i<=600000; i++)
		fac[i]=fac[i-1]*(ll)i%M;

	cin>>n>>k;
	st.clear();
	mp.clear();
	for(int i=1; i<=n*2; i+=2){
		scanf("%lld%lld", &ta[i], &ta[i+1]);
		st.insert(ta[i]);
		st.insert(ta[i+1]);
	}
	int w=1;
	set<ll>::iterator it=st.begin();
	for(; it!=st.end(); it++){
		mp[*it]=w++;
	}
	for(int i=1; i<=n*2; i+=2){
		ta[i]=mp[ta[i]];
		ta[i+1]=mp[ta[i+1]];
		rad(ta[i], ta[i+1], 1);
		c[ta[i]]++;
	}
	ll ans=0;
	for(int i=1; i<=n*2; i++){
		if(c[i]==0) continue;
	//	cout<<i<<" "<<que(i)<<" "<<c[i]<<"\n";
		ans=((ans+C(que(i), k))%M-C(que(i)-c[i], k))%M;
		ans=(ans%M+M)%M;
	}
	ans=(ans%M+M)%M;
	printf("%lld", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define maxn 6000013
#define maxm 213
#define eps 1e-7
#define M (ll)998244353
#define M2 (ll)1000000009
#define inf 1e18
#define pi acos(-1)

ll a[maxn], sum[maxn];
int n;
void add(int p, ll x){
    while(p <= n) sum[p] += x, p += p & -p;
}
void rad(int l, int r, ll x){
    add(l, x), add(r + 1, -x);
}
ll que(int p){
    ll res = 0;
    while(p) res += sum[p], p -= p & -p;
    return res;
}
ll fac[maxn], c[maxn];
ll ta[maxn];
set<ll> st;
map<ll, ll> mp;
int k;
ll qpm(ll a, ll b) {
	a%=M;
	ll res=1;
	while(b>0) {
		if(b&1) res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res;
}
ll C(ll a, ll b){
	if(a<b) return 0;
	ll res=fac[a];
	res=res*qpm(fac[b], M-2)%M*qpm(fac[a-b], M-2)%M;
	return res;
}
int main() {
	fac[0]=fac[1]=1;
	for(int i=2; i<=6000000; i++)
		fac[i]=fac[i-1]*(ll)i%M;

	cin>>n>>k;
	st.clear();
	mp.clear();
	for(int i=1; i<=n*2; i+=2){
		scanf("%lld%lld", &ta[i], &ta[i+1]);
		st.insert(ta[i]);
		st.insert(ta[i+1]);
	}
	int w=1;
	set<ll>::iterator it=st.begin();
	for(; it!=st.end(); it++){
		mp[*it]=w++;
	}
	for(int i=1; i<=n*2; i+=2){
		ta[i]=mp[ta[i]];
		ta[i+1]=mp[ta[i+1]];
		rad(ta[i], ta[i+1], 1);
		c[ta[i]]++;
	}
	ll ans=0;
	for(int i=1; i<=n*2; i++){
		if(c[i]==0) continue;
	//	cout<<i<<" "<<que(i)<<" "<<c[i]<<"\n";
		ans=((ans+C(que(i), k))%M-C(que(i)-c[i], k))%M;
		ans=(ans%M+M)%M;
	}
	ans=(ans%M+M)%M;
	printf("%lld", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define maxn 600013
#define maxm 213
#define eps 1e-7
#define M (ll)998244353
#define M2 (ll)1000000009
#define inf 1e18
#define pi acos(-1)

ll a[maxn], sum[maxn];
int n;
void add(int p, ll x){
    while(p <= n*2) sum[p] += x, p += p & -p;
}
void rad(int l, int r, ll x){
    add(l, x), add(r + 1, -x);
}
ll que(int p){
    ll res = 0;
    while(p) res += sum[p], p -= p & -p;
    return res;
}
ll fac[maxn], c[maxn];
ll ta[maxn];
set<ll> st;
map<ll, ll> mp;
int k;
ll qpm(ll a, ll b) {
	a%=M;
	ll res=1;
	while(b>0) {
		if(b&1) res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res;
}
ll C(ll a, ll b){
	if(a<b) return 0;
	ll res=fac[a];
	res=res*qpm(fac[b], M-2)%M*qpm(fac[a-b], M-2)%M;
	return res;
}
int main() {
	fac[0]=fac[1]=1;
	for(int i=2; i<=600000; i++)
		fac[i]=fac[i-1]*(ll)i%M;

	cin>>n>>k;
	st.clear();
	mp.clear();
	for(int i=1; i<=n*2; i+=2){
		scanf("%lld%lld", &ta[i], &ta[i+1]);
		st.insert(ta[i]);
		st.insert(ta[i+1]);
	}
	int w=1;
	set<ll>::iterator it=st.begin();
	for(; it!=st.end(); it++){
		mp[*it]=w++;
	}
	for(int i=1; i<=n*2; i+=2){
		ta[i]=mp[ta[i]];
		ta[i+1]=mp[ta[i+1]];
		rad(ta[i], ta[i+1], 1);
		c[ta[i]]++;
	}
	ll ans=0;
	for(int i=1; i<=n*2; i++){
		if(c[i]==0) continue;
	//	cout<<i<<" "<<que(i)<<" "<<c[i]<<"\n";
		ans=((ans+C(que(i), k))%M-C(que(i)-c[i], k))%M;
		ans=(ans%M+M)%M;
	}
	ans=(ans%M+M)%M;
	printf("%lld", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define maxn 600013
#define maxm 213
#define eps 1e-7
#define M (ll)998244353
#define M2 (ll)1000000009
#define inf 1e18
#define pi acos(-1)

ll a[maxn], sum[maxn];
int n;
void add(int p, ll x){
    while(p <= n) sum[p] += x, p += p & -p;
}
void rad(int l, int r, ll x){
    add(l, x), add(r + 1, -x);
}
ll que(int p){
    ll res = 0;
    while(p) res += sum[p], p -= p & -p;
    return res;
}
ll fac[maxn], c[maxn];
ll ta[maxn];
set<ll> st;
map<ll, ll> mp;
int k;
ll qpm(ll a, ll b) {
	a%=M;
	ll res=1;
	while(b>0) {
		if(b&1) res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res;
}
ll C(ll a, ll b){
	if(a<b) return 0;
	ll res=fac[a];
	res=res*qpm(fac[b], M-2)%M*qpm(fac[a-b], M-2)%M;
	return res;
}
int main() {
	fac[0]=fac[1]=1;
	for(int i=2; i<=600000; i++)
		fac[i]=fac[i-1]*(ll)i%M;

	cin>>n>>k;
	for(int i=1; i<=n*2; i+=2){
		scanf("%lld%lld", &ta[i], &ta[i+1]);
		st.insert(ta[i]);
		st.insert(ta[i+1]);
	}
	int w=1;
	set<ll>::iterator it=st.begin();
	for(; it!=st.end(); it++){
		mp[*it]=w++;
	}
	for(int i=1; i<=n*2; i+=2){
		ta[i]=mp[ta[i]];
		ta[i+1]=mp[ta[i+1]];
		rad(ta[i], ta[i+1], 1);
		c[ta[i]]++;
	}
	ll ans=0;
	for(int i=1; i<=n*2; i++){
		if(c[i]==0) continue;
	//	cout<<i<<" "<<que(i)<<" "<<c[i]<<"\n";
		ans=((ans+C(que(i), k))%M-C(que(i)-c[i], k))%M;
		ans=(ans%M+M)%M;
	}
	ans=(ans%M+M)%M;
	printf("%lld", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define maxn 600013
#define maxm 213
#define eps 1e-7
#define M (ll)998244353
#define M2 (ll)1000000009
#define inf 1e18
#define pi acos(-1)

ll a[maxn], sum[maxn];
int n;
void add(int p, ll x){
    while(p <= n) sum[p] += x, p += p & -p;
}
void rad(int l, int r, ll x){
    add(l, x), add(r + 1, -x);
}
ll que(int p){
    ll res = 0;
    while(p) res += sum[p], p -= p & -p;
    return res;
}
ll fac[maxn], c[maxn];
ll ta[maxn];
set<ll> st;
map<ll, ll> mp;
int k;
ll qpm(ll a, ll b) {
	a%=M;
	ll res=1;
	while(b>0) {
		if(b&1) res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res;
}
ll C(ll a, ll b){
	if(a<b) return 0;
	ll res=fac[a];
	res=res*qpm(fac[b], M-2)%M*qpm(fac[a-b], M-2)%M;
	return res;
}
int main() {
	fac[0]=fac[1]=1;
	for(int i=2; i<=600000; i++)
		fac[i]=fac[i-1]*(ll)i%M;

	cin>>n>>k;
	for(int i=1; i<=n*2; i+=2){
		scanf("%lld%lld", &ta[i], &ta[i+1]);
		st.insert(ta[i]);
		st.insert(ta[i+1]);
	}
	int w=1;
	set<ll>::iterator it=st.begin();
	for(; it!=st.end(); it++){
		mp[*it]=w++;
	}
	for(int i=1; i<=n*2; i+=2){
		ta[i]=mp[ta[i]];
		ta[i+1]=mp[ta[i+1]];
		rad(ta[i], ta[i+1], 1);
		c[ta[i]]++;
	}
	ll ans=0;
	for(int i=1; i<=n*2; i++){
		if(c[i]==0) continue;
	//	cout<<i<<" "<<que(i)<<" "<<c[i]<<"\n";
		ans=((ans+C(que(i), k))%M-C(que(i)-c[i], k))%M;
	}
	ans=(ans%M+M)%M;
	printf("%lld", ans);
	return 0;
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF);
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) {
		      cout << n << " " << m << endl;
		      int buffer = 0;
		      rep(i, 0, n) {
			trav(e, originalg[i]) {
			  cout << i << " " << e.to << " ";
			  buffer += 2;
			  if (buffer == 50){ cout << '\n'; buffer = 0;}
			}
		      }
		      cout << '\n';
		    }

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    /*
		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }
		    */

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      while (!path.empty()) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	while(extendpath()) {}
	if (dbg) cout << "Cannot extend path anymore" << endl;

	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}
	if (!pairup()) break;

	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}
      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi onpath(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto disconnect = [&](int i) {
			trav(e, g[i]) g[e.to].erase({i});
			g[i].clear();
		      };
    auto disconnect_into = [&](int i) {
			     trav(e, g[i]) g[e.to].erase({i});
			   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);
		       onpath[i] = true;
		       changevalue(i, INF);
		       byvalue.erase({value[i], i});
		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and onpath[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    auto curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});

		    changevalue(candidate, INF);
		    byvalue.erase({value[candidate], candidate});

		    path.pop_back();
		    disconnect(curr);
		    disconnect(candidate);

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (empty(g[i])) continue;
      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << '\n';
	  cout << sz(path) << '\n';
	  trav(node, path) cout << (node + 1) << " "; cout << '\n';
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << '\n';
	  cout << sz(pairings) << '\n';
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << '\n';
	  done = true;
	  break;
	}

      }
      if (done) break;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) {
		      cout << "F_";
		      rep(i, 0, n) {
			trav(e, originalg[i]) {
			  cout << "(" << i << "," << e.to << ")-";
			}
		      }
		    }

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}

      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) {
		      cout << "F_";
		      rep(i, 0, n) {
			trav(e, originalg[i]) {
			  cout << "(" << i << "," << e.to << ")" << endl;
			}
		      }
		    }

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}

      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << '\n';
	  cout << sz(path) << '\n';
	  trav(node, path) cout << (node + 1) << " "; cout << '\n';
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << '\n';
	  cout << sz(pairings) << '\n';
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << '\n';
	  done = true;
	  break;
	}

      }
      if (done) break;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi onpath(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto disconnect = [&](int i) {
			trav(e, g[i]) g[e.to].erase({i});
			g[i].clear();
		      };
    auto disconnect_into = [&](int i) {
			     trav(e, g[i]) g[e.to].erase({i});
			   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);
		       onpath[i] = true;
		       changevalue(i, INF);
		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and onpath[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path)) return false;
		    auto curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    if (val == INF) return false;

		    pairings.PB({curr, candidate});
		    changevalue(candidate, INF);

		    path.pop_back();
		    disconnect(curr);
		    disconnect(candidate);
		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (empty(g[i])) continue;
      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << '\n';
	  cout << sz(path) << '\n';
	  trav(node, path) cout << (node + 1) << " "; cout << '\n';
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << '\n';
	  cout << sz(pairings) << '\n';
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << '\n';
	  done = true;
	  break;
	}

      }
      if (done) break;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) cout << "Failed!" << endl;

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}

      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) {
		      cout << n << " " << m << endl;
		      rep(i, 0, n) {
			cout << i << " : ";
			trav(e, originalg[i]) {
			  cout << e.to << " ";
			}
			cout << endl;
		      }
		    }

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}

      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << '\n';
	  cout << sz(path) << '\n';
	  trav(node, path) cout << (node + 1) << " "; cout << '\n';
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << '\n';
	  cout << sz(pairings) << '\n';
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << '\n';
	  done = true;
	  break;
	}

      }
      if (done) break;
    }
  }
}


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

constexpr auto dbg = false;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{
  int to;
  bool operator < (const edge& o) const {return to < o.to;}
};
using graph = vector<set<edge>>;

const int INF = 1031231234;

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  int origt = T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].insert({v});
      g[v].insert({u});
    }
    auto originalg = g;

    int half = (n + 1) / 2;

    vi value(n, -INF); // value[i] = If i is part of path or pairing, INF.
                       //            Elseif i is adjacent to some node in path, contains smallest index k s.t. i is adjacent to path[k]
                       //            Else, -INF [not adjacent or on path]
    set<pii> byvalue;
    rep(i, 0, n) byvalue.insert({value[i], i});

    vi path;
    vector<pii> pairings;
    vi used(n);
    vi toxic(n);

    auto changevalue = [&](int i, int newvalue) {
			 byvalue.erase({value[i], i});
			 value[i] = newvalue;
			 byvalue.insert({value[i], i});
		       };
    auto usenode = [&](int i) {
		     used[i] = true;
		     changevalue(i, INF);
		     byvalue.erase({value[i], i});
		   };
    auto addtopath = [&](int i) {
		       int pos = sz(path);
		       path.PB(i);

		       usenode(i);

		       trav(e, g[i]) {
			 if (value[e.to] == -INF) changevalue(e.to, pos);
			 else {
			   assert(value[e.to] == INF or value[e.to] < pos);
			 }
		       }
		     };
    auto extendpath = [&]() -> bool {
			if (empty(path)) return false;
			auto i = path.back();
			while (!empty(g[i]) and used[begin(g[i]) -> to])
			  g[i].erase(begin(g[i]));
			if (!empty(g[i])) {
			  auto nxt = begin(g[i]) -> to;
			  addtopath(nxt);
			  return true;
			} else return false;
		      };
    auto pairup = [&]() -> bool {
		    if (dbg) cout << "Trying to pairup now" << endl;
		    if (empty(path) or empty(byvalue)) return false;
		    int curr = path.back();
		    auto [val, candidate] = *begin(byvalue);

		    if (dbg) cout << "Considering pairing " << curr << " and " << candidate << endl;

		    assert(curr != candidate);
		    pairings.PB({curr, candidate});
		    assert(!used[candidate]);
		    if (toxic[curr]) {
		      cout << n << " " << m << endl;
		      int buffer = 0;
		      rep(i, 0, n) {
			trav(e, originalg[i]) {
			  cout << i << " " << e.to << " ";
			  buffer += 2;
			  if (buffer == 50) cout << '\n';
			}
		      }
		      cout << '\n';
		    }

		    trav(e, originalg[candidate]) {
		      toxic[e.to] = true;
		    }

		    usenode(candidate);
		    path.pop_back();

		    while (!empty(byvalue) and rbegin(byvalue) -> first > sz(path)) {
		      auto node = rbegin(byvalue) -> second;
		      changevalue(node, -INF);
		    }

		    return true;
		  };

    bool done = false;
    rep(i, 0, n) {
      if (used[i]) continue;

      if (dbg) cout << "Starting with node " << i << endl;
      addtopath(i);
      bool progress = true;
      while (!done and progress) {
	if (dbg) {cout << "Current path: "; trav(it, path) cout << it << " "; cout << endl;}
	if (dbg) {cout << "Current pairings: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;}
	progress = false;
	while(extendpath()) {
	  if (dbg) {
	    cout << "Extending path to: "; trav(it, path) cout << it << " "; cout << endl;
	  }
	  progress = true;
	}
	if (dbg) cout << "Cannot extend path anymore" << endl;
	if (sz(path) >= half) {
	  cout << "PATH" << " ";
	  cout << sz(path) << " ";
	  trav(node, path) cout << (node + 1) << " "; cout << " ";
	  done = true;
	  break;
	}

	if (pairup()) {
	  if (dbg) {
	    cout << "Making pair: "; trav(elem, pairings) cout << "(" << elem.first << ", " << elem.second << ") "; cout << endl;
	  }
	  progress = true;
	}
	if (2 * sz(pairings) >= half) {
	  cout << "PAIRING" << " ";
	  cout << sz(pairings) << " ";
	  for (const auto& [a, b]: pairings) cout << (a + 1) << " " << (b + 1) << " ";
	  done = true;
	  break;
	}

      }
      if (done) break;
    }

    if (origt == 5000 and abs(origt - T) == 73) {
      cout << endl;
      cout << n << " " << m << endl;
      rep(i, 0, n) {
	cout << i << " : "; trav(e, g[i]) cout << e.to << " "; cout << endl;
      }
      return 0;
    }
  }
}