#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<long long> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i * i <= 1000000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(long long j = i * 2; j * j <= 1000000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = 0;
            b:
            while(n % prime[i] != 0 && i < prime.size()) {
                i ++;
            }
            if(n / prime[i] > k) {
                i ++;
                goto b;
            }
            if(i >= prime.size() || n % prime[i] != 0) {
                cout<< n << "\n";
            } else {
                cout<< prime[i] << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(100000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 100000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 100000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    start:
    while(t --) {
        int n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
            goto start;
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = int(prime.size() - 1);
            b:
            while(n % prime[i] != 0 && i > 0) {
                i --;
            }
            if(prime[i] > k) {
                i --;
                goto b;
            }
            if(n % 2 != 0 && i == 0) {
                cout<< n << "\n";
            } else {
                int ans = prime[i];
                int j = 2;
                int max = ans;
                while(j * ans < k) {
                    if(n % (j * ans) == 0) {
                        max = j * ans;
                    }
                    j ++;
                }
                if(n % (ans * j) == 0 && ans * j <= k) {
                    cout<< n / (ans * j) << "\n";
                } else {
                    cout<< n / max << "\n";
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<long long> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i * i <= 1000000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(long long j = i * 2; j * j <= 1000000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = 0;
            b:
            while(n % prime[i] != 0 && i < prime.size()) {
                i ++;
                if(i == prime.size()) {
                    break;
                }
            }
            if(i == prime.size()) {
                cout<< n << "\n";
            } else {
                if(n / prime[i] > k) {
                    i ++;
                    goto b;
                }
                if(i >= prime.size() || n % prime[i] != 0) {
                    cout<< n << "\n";
                } else {
                    cout<< prime[i] << "\n";
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>> t;
    start:
    while(t --) {
        int n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else {
            for(int i = 1; i * i <= n; i ++) {
                if(n % i == 0 && n / i <= k) {
                    cout<< i << "\n";
                    goto start;
                }
            }
            for(int i = int(sqrt(n)); i >= 1; i --) {
                if(n % i == 0 && i <= k) {
                    cout<< n / i << "\n";
                    goto start;
                }
            }
            cout<< n << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 1000000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 1000000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = 0;
            b:
            while(n % prime[i] != 0 && i < prime.size() && n / prime[i] > k) {
                i ++;
            }
            if(i >= prime.size() || n % prime[i] != 0) {
                cout<< n << "\n";
            } else {
                cout<< prime[i] << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 1000000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 1000000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = int(prime.size() - 1);
            b:
            while(n % prime[i] != 0 && i > 0) {
                i --;
            }
            if(prime[i] > k) {
                i --;
                goto b;
            }
            if(n % 2 != 0 && i == 0) {
                cout<< n << "\n";
            } else {
                int ans = prime[i];
                int j = 2;
                int max = ans;
                while(j * ans <= k) {
                    if(n % (j * ans) == 0) {
                        max = j * ans;
                    }
                    j ++;
                }
                cout<< n / max << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 10000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 10000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    start:
    while(t --) {
        int n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
            goto start;
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = int(prime.size() - 1);
            b:
            while(n % prime[i] != 0 && i > 0) {
                i --;
            }
            if(prime[i] > k) {
                i --;
                goto b;
            }
            if(n % 2 != 0 && i == 0) {
                cout<< n << "\n";
            } else {
                int ans = prime[i];
                int j = 2;
                int max = ans;
                while(j * ans < k) {
                    if(n % (j * ans) == 0) {
                        max = j * ans;
                    }
                    j ++;
                }
                if(n % (ans * j) == 0 && ans * j <= k) {
                    cout<< n / (ans * j) << "\n";
                } else {
                    cout<< n / max << "\n";
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 10000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 10000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = int(prime.size() - 1);
            b:
            while(n % prime[i] != 0 && i > 0) {
                i --;
            }
            if(prime[i] > k) {
                i --;
                goto b;
            }
            if(n % 2 != 0 && i == 0) {
                cout<< n << "\n";
            } else {
                int ans = prime[i];
                int j = 2;
                int max = ans;
                while(j * ans <= k) {
                    if(n % (j * ans) == 0) {
                        max = j * ans;
                    }
                    j ++;
                }
                cout<< n / max << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(100000, true);
vector<int> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(int i = 2; i * i <= 100000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(int j = i * 2; j * j <= 100000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    start:
    while(t --) {
        int n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
            goto start;
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = int(prime.size() - 1);
            while(n % prime[i] != 0 && i > 0) {
                i --;
            }
            if(n % 2 != 0 && i == 0) {
                cout<< n << "\n";
            } else {
                int ans = prime[i];
                int j = 2;
                int max = ans;
                while(j * ans < k) {
                    if(n % (j * ans) == 0) {
                        max = j * ans;
                    }
                    j ++;
                }
                if(n % (ans * j) == 0 && ans * j <= k) {
                    cout<< n / (ans * j) << "\n";
                } else {
                    cout<< n / max << "\n";
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>> t;
    start:
    while(t --) {
        int n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else {
            for(int i = 1; i * i <= n; i ++) {
                if(n % i == 0 && n / i <= k) {
                    cout<< i << "\n";
                    goto start;
                }
            }
            cout<< n << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<bool> isPrime(10000000, true);
vector<long long> prime;
void sieve() {
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i * i <= 1000000000; i ++) {
        if(isPrime[i]) {
            prime.push_back(i);
            for(long long j = i * 2; j * j <= 1000000000; j += i) {
                isPrime[j] = 0;
            }
        }
    }
}
int main() {
    sieve();
    int t;
    cin>> t;
    while(t --) {
        long long n, k;
        cin>> n >> k;
        if(k >= n) {
            cout<< 1 << "\n";
        } else if(k == 1) {
            cout<< n << "\n";
        } else {
            int i = 0;
            b:
            while(n % prime[i] != 0 && i < prime.size() && n / prime[i] > k) {
                i ++;
            }
            if(i >= prime.size() || n % prime[i] != 0) {
                cout<< n << "\n";
            } else {
                cout<< prime[i] << "\n";
            }
        }
    }
    return 0;
}


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
               for(int i=n-1;i>=sqrt(n);i--){
                if(n%i==0){
                    ans=n/i;
                    break;
                }
               }
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<k) cout<<1<<endl;
            else{
                int ans=0;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){
                    if(n%primes[i]==0){
                        ans=primes[i];
                        break;
                    }
                }
                if(ans==0) ans=n;
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){
                    if(n%primes[i]==0 && n/primes[i] <=k){
                        ans=primes[i];
                        break;
                    }
                }
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                vector<int> v;
                for(int i=0;i<primes.size()&&primes[i]<=k;i++){
                    if(n%primes[i]==0)
                        v.push_back(primes[i]);
                }
                if(v.size()>0)
                sort(v.begin(),v.end());
                if(v.size()==0) cout<<n<<endl;
                else
                {

                    cout<<n/v[v.size()-1]<<endl;
                }
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                for(int i=0;i<primes.size();i++){
                    if(primes[i]>k) break;
                    if(n%primes[i]==0){
                        ans=primes[i];
                        break;
                    }
                }
                                    cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                int temp;
                for(int i=2;i*i<=n;i++){
                    if(n%i==0){
                        temp=n/i;
                        if(i<=k)
                            ans=min(ans,n/i);
                        if(temp<=k)
                            ans=min(ans,n/temp);
                    }
                }
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                for(int i=0;i<primes.size();i++){
                    if(primes[i]>k) break;
                    if(n%primes[i]==0 && (n/primes[i]) <=k){
                        ans=primes[i];
                        break;
                    }
                }
                                    cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                vector<int> v;
                for(int i=0;i<primes.size()&&primes[i]<=k;i++){
                    if(n%primes[i]==0)
                        v.push_back(primes[i]);
                }
                if(v.size()>0)
                sort(v.begin(),v.end());
                if(v.size()==0) cout<<n<<endl;
                else
                {
                    int ans=0;
                    for(int i=0;i<v.size();i++){
                        if(n%v[i]==0 && n/v[i]<=k){
                            ans=v[i];
                            break;
                        }
                        ans=n/v[i];
                    }
                    cout<<ans<<endl;
                }
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=0;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){

                    if(primes[i]>k) break;
                    if(n%primes[i]==0){
                        ans=primes[i];
                        break;
                    }
                }
                if(ans==0) ans=n;
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){
                    if(n%primes[i]==0 && n/primes[i] <=k){
                        ans=primes[i];
                        break;
                    }
                    else if(n%primes[i]==0)
                    ans=n/primes[i];
                }
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<=k) cout<<1<<endl;
            else{
                int ans=n;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){
                    if(n%primes[i]==0 && n/primes[i] <=k){
                        ans=primes[i];
                        break;
                    }
                    ans=n/primes[i];
                }
                cout<<ans<<endl;
            }
    }
    }


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

    ll mod=1000000007;
    vector<int> primes;
    vector<int> v;
    void func(){
    int N=pow(10,6);
     vector<bool> isPrime(N + 1, true);
        isPrime[0] = false;
        isPrime[1] = false;

        // Sieve of Erastothenes
        for(int i = 2; i <= N; i++) {
            if (!isPrime[i]) continue;
            if (i > N / i) break;
            for (int j = i * i; j <= N; j += i) isPrime[j] = false;

        }

        for(int i=2;i<=N;i++){
            if(isPrime[i]){
                primes.push_back(i);
            }
            //cout<<isPrime[i]<<endl;
        }

    }

    main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        func();
        int n,k,t;
        cin>>t;
        while(t--){
            cin>>n>>k;
            if(n<k) cout<<1<<endl;
            else{
                int ans=0;
                for(int i=0;i<primes.size() && primes[i]<=k;i++){

                    if(primes[i]>k) break;
                    if(n%primes[i]==0){
                        ans=primes[i];
                        break;
                    }
                }
                if(ans==0) ans=n;
                cout<<ans<<endl;
            }
    }
    }


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,ans;
        cin>>n>>k;
        for (i=1;i<=k && i*i <=n ;i++){
            if (n%i==0){
                if (n/i <=k){
                    ans=min(n/i,i);
                }
                else{
                    ans=n/i;
                }
            }
        }
        cout<<ans<<endl;

    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,a,ans;
        cin>>n>>k;
        ans=n;
        if (n<=k ){
            cout<<1<<endl;
        }
        else{
            for (i=1;i<=k && i*i<=n;i++){
                if (n%i ==0){
                    a=i;

                if (n/a <=k){
                    ans=min(n/a,a);
                }
                else{
                    ans=n/a;
                }
                }
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,a;
        cin>>n>>k;
        if (n<=k ){
            cout<<1<<endl;
        }
        else{
            for (i=1;i<=k && i*i<=n;i++){
                if (n%i ==0){
                    a=i;
                }
            }
            cout<<n/a<<endl;
        }
    }

    return 0;
}


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

long long  funck(long long  n,long long  k){
    long long  s=pow(n,0.5);
    long long  i,flg=0,ans;
    if (k==1){return (n);}
    for (i=2;i<=s;i++){
        if (n%i ==0){
            ans=i;
            flg=1;
            break;
        }
    }
        if (flg==0){
            ans=n;
        }
        return (ans);

}
int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,p;
        cin>>n>>p;
        if (n<=p){
            cout<<1<<endl;
        }

        else{
            cout<<funck(n,p)<<endl;
        }
    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,a,ans;
        cin>>n>>k;
        ans=n;
        if (n<=k ){
            cout<<1<<endl;
        }
        else{
            for (i=1;i<=k && i*i<=n;i++){
                if (n%i ==0){
                    a=i;

                ans=min(n/a,a);

                if (n/i <=k){
                    ans=min(ans,a);
                }
                }
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,ans,m;
        cin>>n>>k;
        ans=n;
        for (i=1;i<=k && i*i <=n ;i++){
            if (n%i==0){
                if (n/i <=k){
                    m=min(n/i,i);
                    ans=min(m,ans);
                }
                else{
                    ans=min(ans,n/i);
                }
            }
        }
        cout<<ans<<endl;

    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,a;
        cin>>n>>k;
        if (n<=k ){
            cout<<1<<endl;
        }
        else{
            for (i=1;i<=k && i*i<=n;i++){
                if (n%i ==0){
                    a=i;
                }
            }
            if (n/a <=k){
                cout<<min(n/a,a)<<endl;
            }
            else{
                cout<<n/a<<endl;
            }
        }
    }

    return 0;
}


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

long long  funck(long long  n,long long  k){
    long long  s=pow(n,0.5);
    long long  i,flg=0,ans;
    if (k==1){return (n);}
    long long a=1;
    for (i=2;i<=s;i++){
        if (i>k){
            break;
        }
        if (n%i ==0){
            a=i;
        }
    }
    if ((n/a)<=k ){
        return (min(n/a ,a));
    }
    return (n/a);
}
int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,p;
        cin>>n>>p;
        if (n<=p){
            cout<<1<<endl;
        }

        else{
            cout<<funck(n,p)<<endl;
        }
    }

    return 0;
}


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

long long  funck(long long  n,long long  k){
    long long  s=pow(n,0.5);
    long long  i,flg=0,ans;
    if (k==1){return (n);}
    i=2;
    while (i<=s && i<=k){
        if (n%i ==0){
            ans=i;
            flg=1;
            break;
        }
        i++;
    }
        if (flg==0){
            ans=n;
        }
        return (ans);

}
int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,p;
        cin>>n>>p;
        if (n<=p){
            cout<<1<<endl;
        }

        else{
            cout<<funck(n,p)<<endl;
        }
    }

    return 0;
}


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

long long  funck(long long  n,long long  k){
    long long  s=pow(n,0.5);
    long long  i,flg=0,ans;
    if (k==1){return (n);}
    i=2;
    long long a;
    while (i<=s && i<=k){
        if (n%i ==0){
            a=i;
            flg=1;
        }
        i++;
    }
    if (n/a<=a){
        ans=n/a;
    }
    else{
        ans=a;
    }
        if (flg==0){
            ans=n;
        }
        return (ans);

}
int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,p;
        cin>>n>>p;
        if (n<=p){
            cout<<1<<endl;
        }

        else{
            cout<<funck(n,p)<<endl;
        }
    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,k,i,a,ans;
        cin>>n>>k;
        ans=n;
        if (n<=k ){
            cout<<1<<endl;
        }
        else{
            for (i=1;i<=k && i*i<=n;i++){
                if (n%i ==0){
                    a=i;
                }
                if (n/a <=k){
                    ans=min(n/a,a);
                }
                else{
                    ans=n/a;
                }
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long n){
    long long i,s;
    s=pow(n,0.5);
    for (i=2;i<=s;i++){
        if (n%i==0){
            return false;
        }
    }

    return true;
}
long long  funck(long long  n,long long  k){

    long long  i,flg=0,ans;
    if (k==1){return (n);}
    i=k;
    if (is_prime(n)){return (n);}
    while ( i>1){
        if (n%i ==0){

            flg=1;
            break;
        }
        i--;
    }

    if (flg==0){
        ans=n;
    }
    else{
        ans=n/i;
    }
    return (ans);

}

int main(){
    int t;
    cin>>t;
    while (t--){
        long long  n,p;
        cin>>n>>p;
        if (n<=p){
            cout<<1<<endl;
        }

        else{
            cout<<funck(n,p)<<endl;
        }
    }

    return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

int main(){
//o:
int t, n, k, ans;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    ans = n;
    for(int i = 1; i * i <= n; n % 2 == 0 ? i++ : i += 2){
    if(n % i == 0){
       if(i <= k)
          ans = min(ans, n / i);
       if(n / i <= k)
          ans = min(ans, i);
    }
}
printf("%i\n", ans);
}
//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
#define ll  long long
using namespace std;

void solve(int n, int k){
int i = k;
bool f = false;
vector<int> v;
if((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0))
    i--;

for(;i * i >= n; i -= 2){
    if(n % i == 0){
        if(k >= i){
            printf("%i\n", n / i);
            v.clear();
            f = false;
            return;
           }
        else
            v.emplace_back(n), f = true;
    }
}

vector<int>::iterator it = v.end();
if(f){
    do{
    it--;
    if(n / (*it) >= k){
        printf("%i\n", n / (*it));
        v.clear();
        f = false;
        return;
        }
}while(it != v.begin());
}

v.clear();
f = false;
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}

//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

void solve(int n, int k){
vector<int> v;
for(int i = n % 2 == 0 ? 2 : 1; i * i <= n;){
    if(n % i == 0){
       v.emplace_back(i);
       v.emplace_back(n / i);
    }
    if(n % 2 == 0)
        i++;
    else
        i += 2;
}
sort(v.begin(), v.end());
vector<int>::iterator it = v.end();

if(!v.empty()){
    do{
    it--;
    if(k >= *it){
        printf("%i\n", n / (*it));
        return;
        }
}while(it != v.begin());
}
printf("%i\n", n);

}

int main(){
//o:
int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);

    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}
//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

void solve(int n, int k){
vector<int> v;
for(long long i = n; i * i >= n; i--){
    if(n % i == 0){
        if(k >= i){
            printf("%i\n", n / i);
            return;
           }
        else
            v.emplace_back(i);
    }
}

vector<int>::iterator it = v.end();
if(!v.empty()){
    do{
    it--;
    if(k >= n / (*it)){
        printf("%i\n", (*it));
        return;
        }
}while(it != v.begin());
}
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);

    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}

//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
#define ll  long long
using namespace std;

void solve(int n, int k){
int i = k;

if((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0))
    i--;

for(;i >= 1; i -= 2){
    if(n % i == 0 && k >= i){
        printf("%i\n", n / i);
        return;
    }
}
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}
//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
#define ll  long long
using namespace std;

void solve(int n, int k){
int i = k;

if((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0))
    i--;

for(;i * i >= n; i -= 2){
    if(n % i == 0 && k >= i){
        printf("%i\n", n / i);
        return;
    }
}
printf("%i\n", n);
}

int main(){
//o:
int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}
//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

int main(){
//o:
int _, n, k, ans;
for (scanf("%d",&_);_;_--){
    scanf("%i%i", &n, &k);
    ans = n;
    for(int i = 1; i * i <= n; n % 2 == 0 ? i++ : i += 2){
    if(n % i == 0){
       if(i <= k)
          ans = min(ans, n / i);
       if(n / i <= k)
          ans = min(ans, i);
    }
}
printf("%i\n", ans);
}
//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
#define ll  long long
using namespace std;

void solve(int n, int k){
int i = k;
vector<int> v;
if((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0))
    i--;

for(;i * i >= n; i--){
    if(n % i == 0){
        if(k >= i){
            printf("%i\n", n / i);
            v.clear();
            return;
           }
        else
            v.emplace_back(n);
    }
}

vector<int>::iterator it = v.end();
if(!v.empty()){
    do{
    it--;
    if(n / (*it) >= k){
        printf("%i\n", n / (*it));
        v.clear();
        return;
        }
}while(it != v.begin());
}

v.clear();
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}

//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

void solve(int n, int k){
vector<int> v;
for(int i = n;i * i >= n; i--){
    if(n % i == 0){
        if(k >= i){
            printf("%i\n", n / i);
            return;
           }
        else
            v.emplace_back(i);
    }
}

vector<int>::iterator it = v.end();

if(!v.empty()){
    do{
    it--;
    if(k >= n / (*it)){
        printf("%i\n", (*it));
        return;
        }
}while(it != v.begin());
}
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}

//goto o;
return 0;
}


       /* Do it! */
      /*  OMAR  */
#include<bits/stdc++.h>
using namespace std;

void solve(int n, int k){
vector<int> v;
for(unsigned int i = n;i * i >= n; i--){
    if(n % i == 0){
        if(k >= i){
            printf("%i\n", n / i);
            return;
           }
        else
            v.emplace_back(i);
    }
}

vector<int>::iterator it = v.end();

if(!v.empty()){
    do{
    it--;
    if(k >= n / (*it)){
        printf("%i\n", (*it));
        return;
        }
}while(it != v.begin());
}
printf("%i\n", n);
}

int main(){
//o:

int t, n, k;
scanf("%i", &t);
while(t--){
    scanf("%i%i", &n, &k);
    if(k >= n)
        printf("1\n");
    else if(k == 1)
        printf("%i\n", n);
    else
        solve(n, k);
}

//goto o;
return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = (int)sqrt(a);
    int i=2;
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0&&(a/i)<=b) return i;

        }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
bool checkP(int a){
    for(int i=2;i<=(int)(sqrt(a));i++){
        if(a%i==0) return false;
    }
    return true;
}
int frstP(int a,int b){
    int i=2,index=1;
    int x=(int)sqrt(a);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0){
            if(a/i<=b) return i;

         index=i;
         //cout<<index<<endl;
        }
    }
    return index;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else if (checkP(a)) cout<<a<<endl;
        else{
            //cout<<frstP(a,b)<<endl;
            if(a/frstP(a,b)>=frstP(a,b)&&frstP(a,b)<=b) cout<<frstP(a,b)<<endl;
            else cout<<a/frstP(a,b)<<endl;
        }

    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = min((int)sqrt(a),b);
    for(int i=2;i<=x;i++){
        if(a%i==0) return i;
    }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = min((int)sqrt(a),b);
    int i=2,maxn=0;
    for(i=2;i<=x;i++){
        if(a%i==0&&a/i<=b){
           // cout<<i<<endl;
        return i;

        }
    }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
bool checkP(int a){
    for(int i=2;i<=(int)(sqrt(a));i++){
        if(a%i==0) return false;
    }
    return true;
}
int frstP(int a,int b){
    int i=2,index=1;
    int x=(int)sqrt(a);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0){
            if(a/i<=b) return i;

         index=i;
         //cout<<index<<endl;
        }
    }
    return index;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else if (checkP(a)) cout<<a<<endl;
        else{
            if(a/frstP(a,b)<=frstP(a,b)&&min(a/frstP(a,b),frstP(a,b))<=b) cout<<min(a/frstP(a,b),frstP(a,b))<<endl;
            else cout<<max(a/frstP(a,b),frstP(a,b))<<endl;
        }

    }
}#include <iostream>
#include <cmath>
using namespace std;
bool checkP(int a){
    for(int i=2;i<=(int)(sqrt(a));i++){
        if(a%i==0) return false;
    }
    return true;
}
int frstP(int a,int b){
    int i=2,index=1;
    int x=(int)sqrt(a);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0){
            if(a/i<=b) return i;

         index=i;
         //cout<<index<<endl;
        }
    }
    return index;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else if (checkP(a)) cout<<a<<endl;
        else{
            if(a/frstP(a,b)<=frstP(a,b)&&min(a/frstP(a,b),frstP(a,b))<=b) cout<<min(a/frstP(a,b),frstP(a,b))<<endl;
            else cout<<max(a/frstP(a,b),frstP(a,b))<<endl;
        }

    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int i=2;
    int x=(int)sqrt(a);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0&&a/i<=b) return i;

        }
    return a;
}
int frstP1(int a,int b){
    int i=2;
    for(i=b;i>0;i--){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0) return i;

        }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else if(b>(int(sqrt(a)))) cout<<frstP(a,b)<<endl;
        else cout<<a/frstP1(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    for(int i=b;i>0;i--){
        if(a%i==0) return i;
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(b>=a) cout<<1<<endl;
        else cout<<a/frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = min((int)sqrt(a),b);
    for(int i=2;i<=x;i++){
        if(a%i==0) return i;
    }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = min((int)sqrt(a),b);
    int i=2,maxn=0;
    for(i=2;i<=x;i++){
        if(a%i==0) maxn=i;
    }
    if(maxn!=0) return maxn;
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = (int)sqrt(a);
    int i=2;
    for(i=2;i<=x+1;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0&&(a/i)<=b) return i;

        }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int x = (int)sqrt(a);
    int i=2,maxn=0;
    for(i=2;i<=x;i++){
        if(a%i==0&&a/i<=b){
           // cout<<i<<endl;
        return i;

        }
    }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


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

int frstP(long long int a,long long int b){
    long long int i=2,index=a;
    long long int x=min((long long int)sqrt(a),b);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0){
            if(a/i<=b) return i;

         index=a/i;
         //cout<<index<<endl;
        }
    }
    return index;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        long long int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
        }
}


#include <iostream>
#include <cmath>
using namespace std;
int frstP(int a,int b){
    int i=2;
    for(i=2;i<=a;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0&&(a/i)<=b) return i;

        }
    return a;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else cout<<frstP(a,b)<<endl;
    }
}


#include <iostream>
#include <cmath>
using namespace std;
bool checkP(int a){
    for(int i=2;i<=(int)(sqrt(a));i++){
        if(a%i==0) return false;
    }
    return true;
}
int frstP(int a,int b){
    int i=2,index=1;
    int x=(int)sqrt(a);
    for(i=2;i<=x;i++){
        //cout<<a%i<<" "<<a/i<<endl;
        if((a%i)==0){
            if(a/i<=b) return i;

         index=i;
         //cout<<index<<endl;
        }
    }
    return index;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a%b==0) cout<<a/b<<endl;
        else if(b>=a) cout<<1<<endl;
        else if (checkP(a)) cout<<a<<endl;
        else{
            if(a/frstP(a,b)<=frstP(a,b)&&min(a/frstP(a,b),frstP(a,b))<=b) cout<<min(a/frstP(a,b),frstP(a,b))<<endl;
            else cout<<max(a/frstP(a,b),frstP(a,b))<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(k==1)
			cout<<n<<"\n";
			else
			{
					int ans;
					for(int i=2;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					cout<<ans<<"\n";
				}
			}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{	        int ans=0;
					for(int i=2;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(i>ans&&k<=i)
							ans=i;
							if(n/i>ans&&k<=(n/i))
							ans=n/i;
						}
				}
					cout<<n/ans<<"\n";
				}
			}
			}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<n<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
					int ans;
					for(int i=3;i<=sqrt(n);i+=2)
					{
						if(n%i==0)
						{
							ans=i;
							break;
						}
					}
					cout<<ans<<"\n";
				}
			}
		}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(k==1)
			cout<<n<<"\n";
			else
			{
					int ans=0;
					for(int i=2;i<=n/2;i++)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					if(ans==0)
					cout<<n<<"\n";
					else
					cout<<ans<<"\n";
				}
			}
			}
		}


#include<bits/stdc++.h>
using namespace std;
int isprime(int n)
{
	if(n==1)
	return 0;
	for(int i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
		return 0;
	}
	return 1;
}
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<"1"<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
				if(isprime(n))
				cout<<n<<"\n";
				else
				{
					int ans;
					for(int i=3;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							ans=i;
							break;
						}
					}
					cout<<ans<<"\n";
				}
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(k==1)
			cout<<n<<"\n";
			else
			{
					int ans=0;
					for(int i=2;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					if(ans==0)
					cout<<n<<"\n";
					else
					cout<<ans<<"\n";
				}
			}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<n<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
					int ans;
					for(int i=2;i<=sqrt(n);i+=2)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					cout<<ans<<"\n";
				}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<"1"<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
					cout<<n<<"\n";
			}
		}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{	        int ans=0;
					for(int i=1;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(i>ans&&k<=i)
							ans=i;
							if(n/i>ans&&k<=(n/i))
							ans=n/i;
						}
				}
					cout<<n/ans<<"\n";
				}
			}
			}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<"1"<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
					cout<<n<<"\n";
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(k==1)
			cout<<n<<"\n";
			else
			{
					int ans;
					for(int i=2;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					cout<<ans<<"\n";
				}
			}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k>=n)
		cout<<"1"<<"\n";
		else
		{	        int ans=0;
					for(int i=1;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(i>ans&&k>=i)
							ans=i;
							if(n/i>ans&&k>=(n/i))
							ans=n/i;
						}
				}
					cout<<n/ans<<"\n";
				}
			}
			}


#include<bits/stdc++.h>
using namespace std;
int isprime(int n)
{
	if(n==1)
	return 0;
	for(int i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
		return 0;
	}
	return 1;
}
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<"1"<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
				if(isprime(n))
				cout<<n<<"\n";
				else
				{
					int ans;
					for(int i=3;i<=sqrt(n);i+=2)
					{
						if(n%i==0)
						{
							ans=i;
							break;
						}
					}
					cout<<ans<<"\n";
				}
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<n<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
					int ans;
					for(int i=2;i<=sqrt(n);i+=2)
					{
						if(n%i==0)
						{
							ans=i;
							break;
						}
					}
					cout<<ans<<"\n";
				}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<n<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
					int ans;
					for(int i=2;i<=sqrt(n);i++)
					{
						if(n%i==0)
						{
							if(k>=(n/i))
							{
								ans=i;
								break;
							}
						}
					}
					cout<<ans<<"\n";
				}
			}
		}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		if(k==1)
		cout<<"1"<<"\n";
		else if(k>=n)
		cout<<"1"<<"\n";
		else
		{
			if(n%2==0)
			cout<<"2"<<"\n";
			else
			{
					int ans;
					for(int i=3;i<=sqrt(n);i+=2)
					{
						if(n%i==0)
						{
							ans=i;
							break;
						}
					}
					cout<<ans<<"\n";
				}
			}
		}
	}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		for(int i = 1; i * i <= n; i++){
			if(n % i == 0){
				if(i <= k) ans = min(ans, n/i);

				if((n / i) <= k) ans = min(ans, i);

			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= sqrt(n); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) < k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= min(sqrt(n),sqrt(k)); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= n/2; i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) < k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= sqrt(n) && i <= k; i++){
				if(n % i == 0){
					ans = min(ans, n/i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= min(sqrt(n),sqrt(k)); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) < k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		for(int i = 1; i <= k;i++){
			if(n % i == 0){
				ans = min(ans, n / i);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= sqrt(n); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= min(sqrt(k),sqrt(n)); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= sqrt(k); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= max(sqrt(k),sqrt(n)); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) <= k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin >> t;
	while(t--){
		int n, k; cin >> n >> k;
                int ans = INT_MAX;
		if(n <= k) ans = 1;

		else if(k == 1) ans = n;

		else{
			for(int i = 1; i <= sqrt(k); i++){
				if(n % i == 0){
					ans = min(ans, n / i);
					if((n / i) < k){
						ans = min(ans, i);
					}

				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t) {
        int n, k, res=1, flag=0;
        cin>>n>>k;
        if(n<=k) res=1;
        else if(k==1) res=n;
        else {
            int i=2;
            while(i<=sqrt(n)) {
                if(n%i==0 && (n/i)<=k && i<=k) {
                    res=i;
                    flag=1;
                    i=n;
                }
                i++;
            }
            if(flag==0) res=n;
        }
        cout<<res<<endl;
        t--;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t) {
        int n, k, res=1, flag=0, max;
        cin>>n>>k;
        if(n<=k) res=1;
        else if(k==1) res=n;
        else {
            res=n;
            int bg=2;
            while(bg<=sqrt(n)) {
                if(n%bg==0 && (n/bg)<=k) {
                    res=(bg);
                    flag=1;
                }
                bg++;
            }
            if(flag==0) res=n;
        }
        cout<<res<<endl;
        t--;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t) {
        int n, k, res=1, flag=0, max;
        cin>>n>>k;
        if(n<=k) res=1;
        else if(k==1) res=n;
        else {
            int bg=2;
            while(bg<=sqrt(n)) {
                if(n%bg==0) {
                    if((n/bg)<=k) {
                        res=bg;
                        flag=1;
                        break;
                    }
                    if(bg<=k) {
                        res=n/bg;
                        flag=1;
                    }
                }
                bg++;
            }
            if(flag==0) res=n;
        }
        cout<<res<<endl;
        t--;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t) {
        int n, k, res=1, flag=0;
        cin>>n>>k;
        if(n<=k) res=1;
        else if(k==1) res=n;
        else {
            int i=3;
            if(n%2==0) res=2;
            else {
                while(i<=sqrt(n) && (n/i)<=k) {
                    if(n%i==0) {
                        res=i;
                        flag=1;
                        i=n;
                    }
                    i+=2;
                }
                if(flag==0) res=n;
            }
        }
        cout<<res<<endl;
        t--;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t) {
        int n, k, res=1, flag=0, max;
        cin>>n>>k;
        if(n<=k) res=1;
        else if(k==1) res=n;
        else {
            int bg=2;
            while(bg<=sqrt(n)) {
                if(n%bg==0 && ((n/bg)<=k || bg<=k)) {
                    res=bg;
                    flag=1;
                    bg=n;
                }
                bg++;
            }
            if(flag==0) res=n;
        }
        cout<<res<<endl;
        t--;
    }
}


#include <bits/stdc++.h>
using namespace std;
//#include<string>
int lcs( string X, string Y, int m, int n )
{
   int L[m+1][n+1];
   int i, j;

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;

       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;

       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
   return L[m][n];
}
int main() {
	int t,i,j,k;
    cin>>t;
    while(t--)
    {
            string s,t,p;
            cin>>s>>t>>p;
            int s_size=s.size(),t_size=t.size(),p_size=p.size();

            k=lcs(s,t,t_size,s_size);
            if(s_size<=t_size&&k==s_size)
            {

                unordered_map<char,int>s_m,t_m,p_m;
                for(i=0;i<s_size;i++)s_m[s[i]]++;
                for(i=0;i<t_size;i++)t_m[t[i]]++;
                for(i=0;i<p_size;i++)p_m[p[i]]++;
                int ans=1;
                for(auto it:t_m)
                {
                    if(it.second<=s_m[it.first]+p_m[it.first])ans=1;
                    else ans=0;
                }
                if(!ans)cout<<"NO"<<endl;
                else cout<<"YES"<<endl;
            }
            else cout<<"NO"<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include<string>
int lcs( string X, string Y, int m, int n )
{
    int L[m+1][n+1];
   int i, j;

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;

       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;

       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
   return L[m][n];
}
int main() {
	int t,i,j,k;
    cin>>t;
    while(t--)
    {
            string s,t,p;
            cin>>s>>t>>p;
            int s_size=s.size(),t_size=t.size(),p_size=p.size();

                k=lcs(s,t,s_size,t_size);
                if(s_size<=t_size&&k==s_size)
                {

            unordered_map<char,int>s_m,t_m,p_m;
            for(i=0;i<s_size;i++)s_m[s[i]]++;
            for(i=0;i<t_size;i++)t_m[t[i]]++;
            for(i=0;i<p_size;i++)p_m[p[i]]++;
            int ans=1;
            for(auto it:s_m)
            {
                if(it.second+p_m[it.first]>=t_m[it.first])ans=1;
                else ans=0;
            }
            if(!ans)cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
                }
                else cout<<"NO"<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include<string>
int lcs( string X, string Y, int m, int n )
{
   int L[m+1][n+1];
   int i, j;

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;

       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;

       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
   return L[m][n];
}
int main() {
	int t,i,j,k;
    cin>>t;
    while(t--)
    {
            string s,t,p;
            cin>>s>>t>>p;
            int s_size=s.size(),t_size=t.size(),p_size=p.size();

            k=lcs(s,t,s_size,t_size);
            //cout<<s<<":"<<t<<":"<<p<<":"<<s_size<<":"<<t_size<<":"<<p_size<<":"<<k<<":";
            if(s_size<=t_size&&k==s_size)
            {

                unordered_map<char,int>s_m,t_m,p_m;
                for(i=0;i<s_size;i++)s_m[s[i]]++;
                for(i=0;i<t_size;i++)t_m[t[i]]++;
                for(i=0;i<p_size;i++)p_m[p[i]]++;
                int ans=1;
                for(auto it:t_m)
                {
                    if(it.second<=s_m[it.first]+p_m[it.first])ans=1;
                    else {ans=0;break;}
                }

                if(!ans)cout<<"NO"<<endl;
                else cout<<"YES"<<endl;
            }
            else cout<<"NO"<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include<string>
int lcs( string X, string Y, int m, int n )
{
   if (m == 0 || n == 0)
     return 0;
   if (X[m-1] == Y[n-1])
     return 1 + lcs(X, Y, m-1, n-1);
   else
     return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
}
int main() {
	int t,i,j,k;
    cin>>t;
    while(t--)
    {
            string s,t,p;
            cin>>s>>t>>p;
            int s_size=s.size(),t_size=t.size(),p_size=p.size();
            map<char,int>s_m,t_m,p_m;
            for(i=0;i<s_size;i++)s_m[s[i]]++;
            for(i=0;i<t_size;i++)t_m[t[i]]++;
            for(i=0;i<p_size;i++)p_m[p[i]]++;
            int ans=1;
            for(auto it:s_m)
            {
                if(it.second<=t_m[it.first]&&it.second+p_m[it.first]>=t_m[it.first])ans=1;
                else ans=0;
            }
            if(!ans)cout<<"NO"<<endl;
            else
            {
                k=lcs(s,t,s_size,t_size);
                if(s_size<=t_size&&k==s_size)cout<<"YES"<<endl;
                else  cout<<"NO"<<endl;
            }
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include<string>
int lcs( string X, string Y, int m, int n )
{
   int L[m+1][n+1];
   int i, j;

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;

       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;

       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
   return L[m][n];
}
int main() {
	int t,i,j,k;
    cin>>t;
    while(t--)
    {
            string s,t,p;
            cin>>s>>t>>p;
            int s_size=s.size(),t_size=t.size(),p_size=p.size();

            k=lcs(s,t,s_size,t_size);
            //cout<<s<<":"<<t<<":"<<p<<":"<<s_size<<":"<<t_size<<":"<<p_size<<":"<<k<<":";
            if(s_size<=t_size&&k==s_size)
            {

                unordered_map<char,int>s_m,t_m,p_m;
                for(i=0;i<s_size;i++)s_m[s[i]]++;
                for(i=0;i<t_size;i++)t_m[t[i]]++;
                for(i=0;i<p_size;i++)p_m[p[i]]++;
                int ans=1;
                for(auto it:t_m)
                {
                    if(it.second<=s_m[it.first]+p_m[it.first])ans=1;
                    else ans=0;
                }
                if(!ans)cout<<"NO"<<endl;
                else cout<<"YES"<<endl;
            }
            else cout<<"NO"<<endl;
    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[30],b[30];
int main()
{
    int n;
    string s,t,p;
    cin>>n;
    while(n--)
    {
        int flag=0;
        int z1=0,z2=0;
        int ans=0;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        cin>>s>>t>>p;
        for(int i=0,j=0; i<s.size()&&j<t.size();)
        {
            if(s[i]==t[j])
            {
                i++;
                j++;
                ans++;
            }
            else
            {
                j++;
            }
        }
        if(ans<s.size())
        {
            printf("NO\n");
            continue;
        }
        for(int i=0; i<s.size(); i++)
        {
            a[s[i]-'a']++;
        }
        for(int i=0; i<t.size(); i++)
        {
            b[t[i]-'a']++;
        }
        for(int i=0; i<p.size(); i++)
        {
            a[p[i]-'a']++;
        }
        for(int i=0; i<26; i++)
        {
            if(a[i]<b[i])
            {
                flag=1;
                break;
            }
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
char s[205];
char t[205];
char p[205];
int zimu[30];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
      memset(s,0,sizeof(s));
      memset(t,0,sizeof(t));
      memset(p,0,sizeof(p));
      memset(zimu,0,sizeof(zimu));
        cin>>s>>t>>p;
        for(int i=0; i<strlen(p); i++)
        {
            zimu[p[i]-'a']++;
        }
        int i=0;
        int j=0;
        while(1)
        {
            if(s[i]==t[j])
            {
                i++;
                j++;
            }
            else
            {
                    if(zimu[t[j]-'a']>0)
                        {
                        zimu[t[j]-'a']--;
                        j++;
                        }
                        else {
                            cout<<"NO"<<endl;break;
                        }
            }
           if(j==strlen(t)&&i==strlen(s)){cout<<"YES"<<endl;break;}
        }
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int a[30], n, ans; string s, t, p;
int main() {
    cin >> n;
    while (n--) {
        cin >> s >> t >> p;
        for (int i = 0; i < 30; i++) a[i] = 0;
        ans = 0;
        for (int i = 0; i < p.size(); i++) a[p[i] - 'a' + 1] = 1;
        for (int i = 0; i < t.size(); i++) {
            int tmp = t[i];
            if (s[ans] == tmp) ans++;
            else if (a[t[i] - 'a' + 1]) a[t[i] - 'a' + 1]--;
            else {
                cout << "NO\n";
                goto there;
            }
        }
        cout << (ans == s.size() ? "YES\n" : "NO\n");
        there:;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int M=105;
char str1[M],str2[M],str3[M];

bool check(int len){
	for(int i=1; i<=len; i++){
		if(str1[i]!=str2[i]) return 0;
	}
	return 1;
}

void solve(){
	int mp[200]={0};
	scanf("%s %s %s",str1+1,str2+1,str3+1);
	int len1=strlen(str1+1),len2=strlen(str2+1),len3=strlen(str3+1);
	for(int i=1; i<=len3; i++){
		mp[str3[i]]++;
	}
	str1[len1+1]='@'; len1++;
	int l=1;
	for(int i=1; i<=len2; i++){
		if(str1[l]!=str2[i]){
			mp[str2[i]]--;
			if(mp[str2[i]]<0) return (void)puts("NO");
		}else l++;
	}
	if(l!=len1) return (void)puts("NO");
	puts("YES");
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}


//≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
//  Date : Plz press Shift + Ctrl + . in proper Sublime
//  Author : Sakii
//  website : zcqiever.tk
//  I'm so vegetable , QAQ..
//≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈

#include<bits/stdc++.h>
#define re register
#define il inline
#define lowbit(x) x&(-x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T> inline void read(T &s){
    s = 0; re char ch = getchar(); re int w = 0;
    while(!isdigit(ch)) w |= ch == '-', ch = getchar();
    while(isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    if(w) s = -s;
}

namespace Sakii {
    int cnt1[35],jud,cnt2[35];
    string s,t,p;

    il void main() {
        int q;
        read(q);
        while(q--) {
            cin>>s;cin>>t; cin>>p;
            memset(cnt1,0,sizeof(cnt1));
            memset(cnt2,0,sizeof(cnt2));
            for(int i = 0; i < p.size(); i++) { cnt1[p[i]-'a'+1]++;}
            for(int i = 0; i < s.size(); i++) { cnt1[s[i]-'a'+1]++;}
            for(int i = 0; i < t.size(); i++) { cnt2[t[i]-'a'+1]++;}
            jud = 1;
            for(int i = 1; i <= 26; i++) { if(cnt1[i] < cnt2[i]) jud = 0; break;}
            int f = 0;
            for(int i = 0; i < s.size(); i++) {
                while(t[f]!=s[i] && f < t.size()) f++;
                if(f == t.size()) jud = 0;
                if(t[f]==s[i]) f++;
            }
            if(jud==1) printf("YES\n");
            else printf("NO\n");
        }
    return;
    }
}

int main(){
    Sakii::main();
    return 0;
}


#include <cstdio>
#include <cstring>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 105
char s[N],t[N],p[N];
int ls,lt,lp;
int scnt[30],tcnt[30],pcnt[30];
int f[N][N];
int cas;

int main(){
	scanf("%d",&cas);
	while(cas--){
		memset(f,0,sizeof(f));
		memset(scnt,0,sizeof(scnt));  memset(tcnt,0,sizeof(tcnt));  memset(pcnt,0,sizeof(pcnt));
		scanf("%s %s %s",s+1,t+1,p+1);
		ls=strlen(s+1);  lt=strlen(t+1);  lp=strlen(p+1);
		for(int i=1;i<=ls;++i) ++scnt[s[i]-'a'];
		for(int i=1;i<=lt;++i) ++tcnt[t[i]-'a'];
		for(int i=1;i<=lp;++i) ++pcnt[p[i]-'a'];
		bool flag=false;
		for(int i=0;i<26;++i) if(scnt[i]>tcnt[i]) flag=true;
		if(flag){  printf("NO\n"); 	continue;  }
		for(int i=0;i<26;++i) if(scnt[i]+pcnt[i]<tcnt[i]) flag=true;
		if(flag){  printf("NO\n"); 	continue;  }
		for(int i=1;i<=ls;++i){
			for(int j=1;j<=lt;++j){
				if(s[i]==t[j]) f[i][j]=f[i-1][j-1]+1;
				else           f[i][j]=max(f[i-1][j],f[i][j-1]);
			}
		}
		if(f[ls][lt]<ls) printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;

#define MAXN 1000
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

char s[MAXN],p[MAXN],t[MAXN];
int st[MAXN],pt[MAXN],tt[MAXN];
int sl,pl,tl;
int q;
int main()
{
	cin>>q;
	while (q--)
	{
		RPT(i,'a','z'+1)
			st[i]=pt[i]=tt[i]=0;
		bool f=true;
		cin>>s>>t>>p;
		sl=strlen(s);
		tl=strlen(t);
		pl=strlen(p);
		RPT(i,0,sl)
			st[s[i]]++;
		RPT(i,0,tl)
			tt[t[i]]++;
		RPT(i,0,pl)
			pt[p[i]]++;
		RPT(i,'a','z'+1)
			if (st[i]+pt[i]<tt[i] || st[i]>tt[i])
			{
				f=false;
				break;
			}
		if (!f)
		{
			cout<<"NO"<<endl;
			continue;
		}
		int cnt=0;
		RPT(i,0,tl)
		{
			if (t[i]==s[cnt])
				cnt++;
		}
		if (cnt!=sl)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
	return ~~(0^_^0);
}


#include <iostream>
#include <string>
using namespace std;
int a[30], n, ans; string s, t, p;
int main() {
    cin >> n;
    while (n--) {
        cin >> s >> t >> p;
        for (int i = 0; i < 30; i++) a[i] = 0;
        ans = 0;
        for (int i = 0; i < p.size(); i++) a[p[i] - 'a' + 1] = 1;
        for (int i = 0; i < t.size(); i++) {
            int tmp = t[i];
            if (s[ans] == tmp) ans++;
            else if (a[t[i] - 'a' + 1]) a[t[i] - 'a' + 1]--;
            else goto there;
        }
        if (ans == s.size()) cout << "yes\n";
        there:;
        if (ans != s.size()) cout << "no\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
char s[maxn],t[maxn],p[maxn];
int q;
int a[30];
int main()
{
	cin>>q;
	while(q--)
	{
		scanf("%s",s+1);
		scanf("%s",t+1);
		scanf("%s",p+1);
		memset(a,0,sizeof(a));
		int len=strlen(t+1);
		for(int i=1;i<=len;i++)
			a[t[i]-'a']++;
		len=strlen(s+1);
		for(int i=1;i<=len;i++)
			a[s[i]-'a']--;
		len=strlen(p+1);
		for(int i=1;i<=len;i++)
			a[p[i]-'a']--;
		int flag=0;
		for(int i=0;i<30;i++)
			if(a[i]>0)flag=1;
		if(flag)cout<<"NO"<<endl;
		if(flag)continue;
		int n=strlen(t+1);
		len=strlen(s+1);
		int pos=1;
		for(int i=1;i<=len;i++)
		{
			int j;
			for(j=pos+1;j<=n;j++)
				if(t[j]==s[i]){
					pos=j;break;
				}
			if(j>n)flag=1;
		}
		if(flag)cout<<"NO"<<endl;
		if(flag)continue;
		cout<<"YES"<<endl;
	}
}
//1
//ab
//baaa
//aaaaa


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int	n;
	int k[2000],l[2000];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		memset(k,0,sizeof(k));
		memset(l,0,sizeof(l));
		string a,b,c;
		bool y=0;
		cin>>a>>c>>b;
		int alen=a.size(),blen=b.size(),clen=c.size();
		for(int j=0;j<alen;j++)
		k[a[j]]++;
		for(int j=0;j<blen;j++)
		k[b[j]]++;
		for(int j=0;j<clen;j++)
		l[c[j]]++;
		for(int j=95;j<=123;j++)
		{
			if(k[j]<l[j])
			{
				y=1;
				cout<<"NO"<<endl;
				break;
			}
		}
		if(y==0) cout<<"YES"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ss[26], tt[26], need[26], have[26];
#define ZERO(a) memset(a, 0, sizeof(a))

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        string s,t,p;
        cin >> s >> t >> p;

        ZERO(need); ZERO(have);

        for(int i = 0; i < p.size(); i++)
            have[p[i] - 'a']++;

        int j = 0;
        int flag = 0;
        for(int i = 0; i < t.size(); i++)
        {
            if(s[j] == t[i] && j < s.size()) j++;
            else
            {
                if(have[t[i] - 'a'] > 0) --have[t[i] - 'a'];
                else
                {
                    flag = 1;
                    break;
                }
            }
        }
        if(j != s.size()) flag = 1;
        if(flag == 0) puts("YES");
        else puts("NO");
    }

}


//过样例就行了
#include<bits/stdc++.h>
using namespace std;
#define next_ptt(i,j) next_permutation(i,i+j);//字典序依次增大 下一个全排列
#define prev_ptt(i,j) prev_permutation(i,i+j);//字典序依次增大 上一个全排列
#define ms(i,j) memset(i,j,sizeof(i));
typedef long long ll;
const int N=1e6+2;
const int mod=100003;

int main(){
	ios::sync_with_stdio(false);
	int Q;
	cin>>Q;
	while(Q--){
		string s,t,p;
		cin>>s>>t>>p;
		int a[50];
		int k=0;
		int flag=1;
		ms(a,0);
		for(int i=0;i<p.length();i++){
			a[p[i]-'a']++;
		}
		for(int i=0;i<t.length();i++){
			if(t[i]==s[k]) k++;
			else if(a[t[i]-'a']) a[t[i]-'a']--;
			else{
				flag=0;
				break;
			}
		}
		if(k!=s.length()) flag=0;
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}
//wa了就是评测机的问题


#include<cstdio>
#include<cstring>
#define N 105

int T;

char s[N],t[N],p[N];

int cnt[30];

int main(){
	scanf("%d",&T);
	while(T--){
		memset(cnt,0,sizeof(cnt));
		scanf("%s%s%s",s+1,t+1,p+1);
		bool flg=0;
		int ss=strlen(s+1),tt=strlen(t+1),pp=strlen(p+1);
		for(int i=1;i<=ss;i++)
			cnt[s[i]-'a'+1]++;
		for(int i=1;i<=tt;i++)
			cnt[t[i]-'a'+1]--;
		for(int i=1;i<=pp;i++)
			cnt[p[i]-'a'+1]++;
		for(int i=1;i<=26;i++)
			if(cnt[i]<0)
				flg=1;
		if(flg){
			printf("NO\n");
			continue;
		}
		int tmp=1;
		for(int i=1;i<=tt;i++)
			if(t[i]==s[tmp])
				tmp++;
		if(tmp<=ss)
			printf("NO\n");
		else
			printf("YES\n");
	}
}


/*
 * socode.online
 *
 * Author: 沈朗
 * E-mail: 273904941@qq.com
 * Time  : 2020-04-18 18:04:18
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
string s,t1,p;
int a[27],b[27],c[27];
bool isok(string x,string y){
	int p=0;
	for(int i=0;i<y.size();i++){
		if(p==x.size())return 1;
		if(x[p]==y[i]){
			p++;
		}
	}
	if(p==x.size())return 1;
	else return 0;
}
void solve(){
	if(isok(s,t1)==0){
		printf("NO\n");return ;
	}
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<p.size();i++){
		a[p[i]-'a']++;
	}
	for(int i=0;i<s.size();i++){
		b[s[i]-'a']++;
	}
	for(int i=0;i<t1.size();i++){
		c[t1[i]-'a']++;
	}
	for(int i=0;i<27;i++){
		if(a[i]+b[i]<c[i]){
			printf("NO\n");return ;
		}
	}
	printf("YES\n");
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		cin>>s>>t1>>p;
		solve();
//		printf("1\n");
	}
	return 0;
}


/*
 * socode.online
 *
 * Author: 李策
 * E-mail: 691397536@qq.com
 * Time  : 2020-04-18 20:40:00
 */
#include <bits/stdc++.h>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))

typedef long long ll;

int cnt[35];

void gao() {
	string s, t, p;
	cin >> s >> t >> p;
	int lens = s.size(), lent = t.size(), lenp = p.size();
	if( lens > lent || lens+lenp < lent ) {
		cout << "NO\n";
		return ;
	}
	mem(cnt,0);
	for( int i = 0; i < lenp; i++ ) {
		cnt[p[i]-'a']++;
	}
	int poss = 0, post = 0, num = 0;
	while( poss < lens ) {
		if( post >= lent ) {
			cout << "NO\n";
	        return ;
		}
		if( s[poss] != t[post] ) {
			if( cnt[t[post]-'a'] <= 0 ) {
				cout << "NO\n";
	        	return ;
			}
			cnt[t[post]-'a']--, post++, num++;
		}
		else poss++, post++;
	}
	for( int i = lens+num; i < lent; i++ ) {
		if( cnt[t[i]-'a'] <= 0 ) {
			cout << "NO\n";
	        return ;
		}
		cnt[t[i]-'a']--;
	}
	cout << "YES\n";
	return ;
}

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	ios::sync_with_stdio(false);
//	cin.tie(0);
    int t;
    cin >> t;
    while( t-- ) gao();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N
using namespace std;
int cnt1[36],q;
string s,t,p;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>q;
	while(q--){
		cin>>s>>t>>p;
		memset(cnt1,0,sizeof(cnt1));
		for(int i = 0;i < p.length();++i) cnt1[p[i]-'a']++;
		for(int i = 0;i < t.length();++i){
			if(s[i] == t[i]) continue;
			else{
				if(cnt1[t[i]-'a'] > 0){
					cnt1[t[i]-'a']--;
					s.insert(i,1,t[i]);
				}else{
					puts("NO");
					goto tag;
				}
			}
		}
		//cout << s << endl;
		if(s != t) puts("NO");
		else puts("YES");
		tag:continue;
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)

using namespace std;
typedef long long ll;
unordered_map <char, int> SP, T;

inline int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') s = s*10+ch-'0', ch = getchar();
    return s*w;
}

int main() {
    int tt = read();
    while (tt--) {
        string s, t, p;
        cin >> s >> t >> p;
        int ls = s.length(), lt = t.length(), lp = p.length();
        if (ls > lt) {puts("NO"); continue;}
        SP.clear(), T.clear();
        rep(i, 0, ls-1) SP[s[i]]++;
        rep(i, 0, lp-1) SP[p[i]]++;
        rep(i, 0, lt-1) T[t[i]]++;
        bool flg = 0;
        for (char i = 'a'; i <= 'z'; i++)
            if (SP[i] < T[i]) {flg = 1; break;}
        if (flg == 1) {puts("NO"); continue;}
        int S = 0; flg = 0;
        rep(i, 0, lt-1) {
            if (s[S] == t[i]) S++;
            if (S == ls) {flg = 1; break;}
        }
        if (flg == 1) puts("YES");
        else puts("NO");
    }
    return 0;
}


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

#define ll long long
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define ls (rt<<1)
#define rs (rt<<1|1)
#define tmid (t[rt].l+t[rt].r>>1)
#define mid (l+r>>1)
#define mod			//
#define N			//

using namespace std;
string p, s, t;
int cnt[300], Q;
int main(){
	scanf("%d", &Q);
	while(Q--){
		cin >> s >> t >> p;
		memset(cnt, 0, sizeof(cnt));
		for(int i = 0; i < p.size(); i++) cnt[p[i]]++;
		int p = 0, fl = 1;
		for(int i = 0; i < t.size(); i++){
			if(p < s.size() && s[p] == t[i]){
				p++;
				continue;
			}
			if(cnt[t[i]]){
				cnt[t[i]]--;
				continue;
			}
			fl = 0;
			break;
		}
		if(fl) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


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

#define ll long long
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define ls (rt<<1)
#define rs (rt<<1|1)
#define tmid (t[rt].l+t[rt].r>>1)
#define mid (l+r>>1)
#define mod			//
#define N			//

using namespace std;
string p, s, t;
int cnt[300], Q;
int main(){
	scanf("%d", &Q);
	while(Q--){
		cin >> s >> t >> p;
		memset(cnt, 0, sizeof(cnt));
		for(int i = 0; i < p.size(); i++) cnt[p[i]]++;
		int p = 0, fl = 1;
		for(int i = 0; i < t.size(); i++){
			if(p < s.size() && s[p] == t[i]){
				p++;
				continue;
			}
			if(cnt[t[i]]){
				cnt[t[i]]--;
				continue;
			}
			fl = 0;
			break;
		}
		if(fl && p == s.size()) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


/*
 * socode.online
 *
 * Author: shajingxiang
 * E-mail: 3385764576@qq.com
 * Time  : 2020-03-11 18:31:22
 */
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<iostream>

#define ll long long
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define ls (rt<<1)
#define rs (rt<<1|1)
#define tmid (t[rt].l+t[rt].r>>1)
#define mid (l+r>>1)
#define mod			//
#define N			//

using namespace std;
string p, s, t;
int cnt[300], Q;
int main(){
	scanf("%d", &Q);
	while(Q--){
		cin >> s >> t >> p;
		memset(cnt, 0, sizeof(cnt));
		for(int i = 0; i < p.size(); i++) cnt[p[i]]++;
		if(p.size() + s.size() < t.size()){
			printf("NO\n");
			continue;
		}
		int p = 0, fl = 1;
		for(int i = 0; i < t.size(); i++){
			if(s[p] == t[i]){
				p++;
				continue;
			}
			if(cnt[t[i]]){
				cnt[t[i]]--;
				continue;
			}
			fl = 0;
			break;
		}
		if(fl) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


/**
https://codeforces.com/contest/1194/problem/C
**/
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

bool solve(string s, string t)
{
    int i=0;
    for(int j=0; j<(int)t.length(); j++){
        if(s[i] == t[j]) i++;
    }
    if(i == (int)s.length()) return true;
    else return false;
}

int main()
{
    IOS;
    int q;
    while(~scanf("%d", &q))
    {
        while(q--)
        {
            string s, t, p;
            int a[27], b[27], c[27];
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            cin >> s >> t >> p;
            for(int i=0; i<(int)s.length(); i++) a[s[i]-'a']++;
            for(int i=0; i<(int)t.length(); i++) b[t[i]-'a']++;
            for(int i=0; i<(int)p.length(); i++) c[p[i]-'a']++;
            bool b1 = true;
            for(int i=0; i<27; i++){
                if(b[i]!=0 && a[i]+c[i] < b[i]){
                    b1 = false;
                }
            }
            //cout << b1 << endl;
            if(b1 && solve(s,t)){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

string s, t, p;
int a[27], b[27], c[27];

bool solve(string s, string t)
{
    int i=0;
    for(int j=0; j<(int)t.length(); j++){
        if(s[i] == t[j]) i++;
    }
    if(i == (int)s.length()) return true;
    else return false;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int q;
    scanf("%d", &q);
    //while(~scanf("%d", &q))
    {
        while(q--)
        {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            cin >> s >> t >> p;
            for(int i=0; i<(int)s.length(); i++) a[s[i]-'a']++;
            for(int i=0; i<(int)t.length(); i++) b[t[i]-'a']++;
            for(int i=0; i<(int)p.length(); i++) c[p[i]-'a']++;
            bool b1 = true;
            for(int i=0; i<27; i++){
                if(b[i]!=0 && a[i]+c[i] < b[i]){
                    b1 = false;
                }
            }
            //cout << b1 << endl;
            if(b1 && solve(s,t)){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

string s, t, p;
int a[27], b[27], c[27];

bool solve(string s, string t)
{
    int i=0;
    for(int j=0; j<(int)t.length(); j++){
        if(s[i] == t[j]) i++;
    }
    if(i == (int)s.length()) return true;
    else return false;
}

int main()
{
    int q;
    scanf("%d", &q);
    //while(~scanf("%d", &q))
    {
        while(q--)
        {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            cin >> s >> t >> p;
            for(int i=0; i<(int)s.length(); i++) a[s[i]-'a']++;
            for(int i=0; i<(int)t.length(); i++) b[t[i]-'a']++;
            for(int i=0; i<(int)p.length(); i++) c[p[i]-'a']++;
            bool b1 = true;
            for(int i=0; i<27; i++){
                if(b[i]!=0 && a[i]+c[i] < b[i]){
                    b1 = false;
                }
            }
            //cout << b1 << endl;
            if(b1 && solve(s,t)){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }

    }
    return 0;
}


/**
https://codeforces.com/contest/1194/problem/C
**/
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

bool solve(string s, string t)
{
    int i=0;
    for(int j=0; j<(int)t.length(); j++){
        if(s[i] == t[j]) i++;
    }
    if(i == (int)s.length()) return true;
    else return false;
}

int main()
{
    IOS;
    int q;
    scanf("%d", &q);
    //while(~scanf("%d", &q))
    {
        while(q--)
        {
            string s, t, p;
            int a[27], b[27], c[27];
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            cin >> s >> t >> p;
            for(int i=0; i<(int)s.length(); i++) a[s[i]-'a']++;
            for(int i=0; i<(int)t.length(); i++) b[t[i]-'a']++;
            for(int i=0; i<(int)p.length(); i++) c[p[i]-'a']++;
            bool b1 = true;
            for(int i=0; i<27; i++){
                if(b[i]!=0 && a[i]+c[i] < b[i]){
                    b1 = false;
                }
            }
            //cout << b1 << endl;
            if(b1 && solve(s,t)){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

bool solve(string s, string t)
{
    int i=0;
    for(int j=0; j<(int)t.length(); j++){
        if(s[i] == t[j]) i++;
    }
    if(i == (int)s.length()) return true;
    else return false;
}

int main()
{
    IOS;
    int q;
    scanf("%d", &q);
    //while(~scanf("%d", &q))
    {
        while(q--)
        {
            string s, t, p;
            int a[27], b[27], c[27];
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            cin >> s >> t >> p;
            for(int i=0; i<(int)s.length(); i++) a[s[i]-'a']++;
            for(int i=0; i<(int)t.length(); i++) b[t[i]-'a']++;
            for(int i=0; i<(int)p.length(); i++) c[p[i]-'a']++;
            bool b1 = true;
            for(int i=0; i<27; i++){
                if(b[i]!=0 && a[i]+c[i] < b[i]){
                    b1 = false;
                }
            }
            //cout << b1 << endl;
            if(b1 && solve(s,t)){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string S, T, P;
int lS;
int lT;
int lP;
int remain[26];

int main() {
//    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> S >> T >> P;
        lS = S.length();
        lT = T.length();
        lP = P.length();
        if (lS > lT)
        cout << "NO" << endl;
		else
		{
            memset(remain, 0, sizeof(remain));
            for (int j = 0; j < lP; ++j)
                remain[P[j] - 'a']++;
            int index = 0;
            bool v = true;
            for (int j = 0; j < lT; ++j)
			{
                if (index < lS && T[j] == S[index])
                    index++;
				else
				{
                    int& r = remain[T[j] - 'a'];
                    if (r <= 0)
					{
                        v = false;
                        break;
                    }
                    --r;
                }
            }
            if (v && index == lS)
            cout << "YES" << endl;
			else
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q;
string s,t,p;
int counts[30];
int countt[30];
int countp[30];
int vis[30];
int main()
{
	cin>>q;
	while(q--)
	{
		int flag=0;
		memset(counts,0,sizeof(counts));
		memset(countt,0,sizeof(countt));
		memset(countp,0,sizeof(countp));
		memset(vis,0,sizeof(vis));
		cin>>s>>t>>p;
		for(int i=0;i<s.length();i++)
		counts[s[i]-'a']++;//0-25
		for(int i=0;i<t.length();i++)
		countt[t[i]-'a']++;//0
		for(int i=0;i<p.length();i++)
		countp[p[i]-'a']++;//0

		for(int i=0;i<=25;i++)
		{
			if(counts[i]>countt[i])
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
		}
			for(int i=0;i<=25;i++)
		{
			if(counts[i]+countp[i]<countt[i])
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
		}
		int pos=t.find(s[0]);
		vis[s[0]-'a']=1;
		for(int i=1;i<s.length();i++)
		{
			if(pos>t.find(s[i])&&vis[s[i]-'a']==0&&t.find(s[i])!=t.npos)
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
			else
			{
			pos=t.find(s[i]);
			vis[s[i]-'a']=1;
		    }
		}
		if(flag==0)
		cout<<"YES"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q;
string s,t,p;
int viss[30];
int vist[30];
int visp[30];
int vis[30];
int main()
{
	cin>>q;
	while(q--)
	{
		int flag=0;
		memset(viss,0,sizeof(viss));
		memset(vist,0,sizeof(viss));
		memset(visp,0,sizeof(viss));
		memset(vis,0,sizeof(vis));
		cin>>s>>t>>p;
		for(int i=0;i<s.length();i++)
		viss[s[i]-'a']++;//0-25
		for(int i=0;i<t.length();i++)
		vist[t[i]-'a']++;//0
		for(int i=0;i<p.length();i++)
		visp[p[i]-'a']++;//0

		for(int i=0;i<=25;i++)
		{
			if(viss[i]>vist[i])
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
		}
			for(int i=0;i<=25;i++)
		{
			if(viss[i]+visp[i]<vist[i])
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
		}
		int pos=t.find(s[0]);
		vis[s[0]-'a']=1;
		for(int i=1;i<s.length();i++)
		{
			if(pos>t.find(s[i])&&vis[s[i]-'a']==0)
			{
				cout<<"NO"<<endl;
				flag=1;
				break;
			}
			else
			{
			pos=t.find(s[i]);
			vis[s[i]-'a']=1;
		    }

		}
		if(flag==0)
		cout<<"YES"<<endl;
	}
	return 0;
}