#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long p[65];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 31) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(p[side * 2] , useless) || p[side * 2] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    p[0] = 1;
    for (int i = 1 ;i <= 60 ;i++)
        p[i] = p[i - 1] * 2;

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
    return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

bool add_overflow(long long a , long long b) {
    long long t;
    return __builtin_add_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    if (k > s[side]) {
        cout << "NO\n";
        return;
    }

    long long squares = 1 , len = 1;
    while (side) {
        if (k > squares) {
            k -= squares;
            squares *= 4;
            len = len * 2 + 1;
        } else {
            if (squares - k >= len) {
                cout << "YES " << side << '\n';
                return;
            } else if (k >= len) {
                cout << "YES " << side - 1 << '\n';
                return;
            } else
                break;
        }

        side--;
    }

    cout << "NO\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }

        k -= s[side] * useless;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
        cout << s[i] << endl;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }

        k -= s[side] * useless;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
    return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

bool add_overflow(long long a , long long b) {
    long long t;
    return __builtin_add_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    if (s[side] < k) {
        cout << "NO\n";
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }

        k -= s[side] * useless;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 0 ; i < 35 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
    return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

bool add_overflow(long long a , long long b) {
    long long t;
    return __builtin_add_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    if (k > s[side]) {
        cout << "NO\n";
        return;
    }

    long long squares = 1 , len = 1;
    while (side) {
        if (k > squares) {
            k -= squares;
            squares *= 4;
            len = len * 2 + 1;
            side--;
        } else {
            long long need = (k + s[side] - 1) / s[side];
            if (k >= len) {
                cout << "YES " << side - 1 << '\n';
                return;
            }
            else if (squares - need >= len) {
                cout << "YES " << side << '\n';
                return;
            }
            else
                break;
        }
    }

    cout << "NO\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long p[65];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 31) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(p[side * 2] , useless) || p[side * 2] * useless > k) {
            cout << "YES " << side << '\n';
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    p[0] = 1;
    for (int i = 1 ;i <= 60 ;i++)
        p[i] = p[i - 1] * 2;

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 32) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 35 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
    return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

bool add_overflow(long long a , long long b) {
    long long t;
    return __builtin_add_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    long long squares = 1 , len = 1;
    while (side) {
        if (k > squares) {
            k -= squares;
            squares *= 4;
            len = len * 2 + 1;
        } else {
            if (squares - k >= len) {
                cout << "YES " << side << '\n';
                return;
            } else if (k >= len) {
                cout << "YES " << side - 1 << '\n';
                return;
            } else
                break;
        }

        side--;
    }

    cout << "NO\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 30) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }

        k -= s[side] * useless;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    debug << s[31];
    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
        return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 31) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 0 ; i < 35 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <bits/stdc++.h>

using namespace std;

template <class X, class Y>
ostream & operator << (ostream & os, const pair <X, Y>& p) {
    return os << "[" << p.first << ", " << p.second << "]" ;
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, const Container& x) {
    os << "{";
    bool f = 1;
    for (auto&y : x) {
        if (!f) os << ", ";
        else f = 0;
        os << y;
    }
    return os << "}";
}

struct Debug {
#ifndef ONLINE_JUDGE
    template<class T>
    Debug& operator << (const T& x) {
        cerr << x << " , ";
    return *this;
    }
    ~Debug() {cerr << endl;}
#define debug cerr << "Line(" << __LINE__ << ") : " , Debug()
#else
    template<class T>
    Debug& operator << (const T& x) {
        return *this;
    }
    #define debug Debug()
#endif
};

long long s[35];

bool mul_overflow(long long a , long long b) {
    long long t;
    return __builtin_mul_overflow(a , b , &t);
}

bool add_overflow(long long a , long long b) {
    long long t;
    return __builtin_add_overflow(a , b , &t);
}

void run() {
    long long side , k;
    cin >> side >> k;

    if (side >= 29) {
        cout << "YES " << side - 1 << '\n';
        return;
    }

    if (s[side] < k) {
        cout << "NO\n";
        return;
    }

    long long count = 1;
    while (k) {
        if (k < count || side == 0) {
            cout << "NO\n";
            return;
        }

        k -= count;
        long long all = count * 4;
        count = count * 2 + 1;
        long long useless = all - count;
        side--;

        if (mul_overflow(s[side] , useless) || s[side] * useless >= k) {
            cout << "YES " << side << '\n';
            return;
        }

        k -= s[side] * useless;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    long long add = 1 , all = 0;
    for (int i = 1 ; i < 32 ;i++) {
        all += add;
        add *= 4;
        s[i] = all;
    }

    int t;
    cin >> t;
    while (t--)
        run();
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && k == 3) {
            cout << "NO\n";
            continue;
        }
        if(n >= 31 || maxk(n-1) >= k-1) {
            cout << "YES " << n-1 << endl;
            continue;
        }
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk <= k && na > 0){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << "YES " << na << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && k == 3) {
            cout << "NO\n";
            continue;
        }
        if(n >= 31 || maxk(n-1) >= k-1) {
            cout << "YES " << n-1 << endl;
            continue;
        }
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk <= k){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << "YES " << na << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && (k == 2 || k == 3)) {
            cout << "NO\n";
            continue;
        }
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk <= k){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << "YES " << na << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n < 32 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && k == 3) {
            cout << "NO\n";
            continue;
        }
        if(n > 31 || maxk(n-1) >= k-1) {
            cout << "YES " << n-1 << endl;
            continue;
        }
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk <= k && na > 0){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << "YES " << na << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        cout << "YES ";
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk < k){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << na << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && k == 3) {
            cout << "NO\n";
            continue;
        }
        if(n >= 31 || maxk(n-1) >= k-1) {
            cout << "YES " << n-1 << endl;
            continue;
        } else cout << "YES 0" << endl;
    }
}


#include <iostream>

using namespace std;

int64_t maxk(int64_t n){
    int64_t ans = 1;
    while(n--) ans *= 4;
    return (ans-1)/3;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int64_t n, k;
        cin >> n >> k;
        if(n <= 30 && (maxk(n) < k)) {
            cout << "NO\n";
            continue;
        }
        if(n == 2 && k == 3) {
            cout << "NO\n";
            continue;
        }
        int64_t ka = 1, dk = 3, na = n-1;
        while(ka+dk <= k){
            ka += dk;
            dk = dk*2+1;
            na--;
        }
        cout << "YES " << na << endl;
    }
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l){
                    cout<<"NO\n";
                    break;
                }
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<min(64,n);i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=1;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(int i=0;i<64;i++){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                l=l+(1LL<<(i+1))-1;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i;j++){
                    r=add(r,mul(mul((n-i+j),f[n-i]),g[j]));
                }
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<=min(64,(int)n);i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<min(64,(int)n);i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
const ll inf=(ll)1e18+1;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,inf);
}
ll mul(ll a,ll b){
 return (LD)a*(LD)b>(LD)inf?inf:a*b;
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<=min(63,(int)n);i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=inf;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l){
                    cout<<"NO\n";
                    break;
                }
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
        cout<<"NO\n";
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n])break;
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
        cout<<"NO\n";
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(int i=0;i<64;i++){
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                l=l+(1LL<<(i+1))-1;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i;j++){
                    r=add(r,mul(mul((n-i+j),f[n-i]),g[j]));
                }
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
        cout<<"NO\n";
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l){
                    cout<<"NO\n";
                    break;
                }
                l=add(l,p-1);
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i;j++){
                    r=add(r,mul((n-i+j),g[j]));
                }
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
const ll inf=(ll)1e18+1;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)inf);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)inf);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<=min(63,(int)n);i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=inf;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            break;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
        cout<<"NO\n";
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64&&n-i-1>=0;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l){
                    cout<<"NO\n";
                    break;
                }
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n])break;
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
        cout<<"NO\n";
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]){
            cout<<"NO\n";
            continue;
        }
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    goto nxt;
                }
                if(k<l)break;
                l=add(l,p-1);
                r=l;
                if(n>=100) r=1e18+1;
                else for(int j=0;j<=i&&n-i-1>=0;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
            cout<<"NO\n";
        }
        nxt:;
    }
	return 0;
}


#include<bits/stdc++.h>
#define PB push_back
#define X first
#define Y second
#define FIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef double LD;
typedef pair<int,int> pii;
const int maxn=3e5+10;
ll t,n,k;
ll f[100],g[100];
ll add(ll a,ll b){
 return min(a+b,(ll)1e18+1);
}
ll mul(ll a,ll b){
 return min((LD)a*(LD)b,(LD)1e18+1);
}
int main(){
    FIO;
    cin>>t;
    g[0]=1;
    for(ll i=1;i<100;i++) g[i]=add(mul(g[i-1],2),3);
    f[0]=0;
    for(ll i=1,p=1;i<100;i++,p=mul(p,4)) f[i]=add(f[i-1],p);
    for(int ca=0;ca<t;++ca){
        cin>>n>>k;
        if(n<100&&k>f[n]) cout<<"NO\n";
        else{
            ll l=0,r=0;
            for(ll i=0,p=2;i<64;i++,p=mul(p,2)){
                //cout<<"L"<<l<<"R"<<r<<endl;
                if(k>=l&&k<=r){
                    cout<<"YES "<<n-i<<endl;
                    break;
                }
                if(k<l){
                    cout<<"NO\n";
                    break;
                }
                l=add(l,p-1);
                r=l;
                if(n>100) r=1e18+1;
                else for(int j=0;j<=i;j++){
                    r=add(r,mul(f[n-j-1],g[j]));
                }
            }
        }
    }
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<vector>

using namespace std;

typedef long long ll;

ll n, k, a[100];

int main(){
    int T;
    scanf("%d", &T);
    ll sum = 1;
    a[1] = 1;
    for (int i = 2; i <= 31; i++){
        a[i] = a[i-1]+sum*4;
        sum *= 4;
    }
    while (T--){
        cin>>n>>k;
        if (n <= 31){
            bool flag = false;
            if (a[n] < k || (n == 2 && k == 3)){
                puts("NO");
                continue;
            }
            ll t = 1, add = 1, cnt = 0;
            for (int i = 0; ; i++){
                t = t*2+1;
                cnt++;
                if (cnt >= n || t*2+1 > k)
                    break;
            }
            printf("YES %lld\n", n-cnt);
        }
        else printf("YES %lld\n", n-1);
    }
}


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

using namespace std;

typedef long long ll;

ll n, m;

int main(){
	int T;
	scanf("%d", &T);
	while (T--){
		scanf("%lld%lld", &n, &m);
		ll sum = 1, add = 1;
		for (int i = 1; i < n && i < 30; i++){
			sum += add*4;
			add *= 4;
		}
		if (sum < m){
			puts("NO");
			continue;
		}
		if (n >= 32){
			printf("YES %lld\n", n-1);
		}
		else{
			ll t = 1, cnt = 0;
			while (t < m){
				t = t*2+1;
				cnt++;
				if (cnt > 31) break;
			}
			if (t >= m) t = (t-1)/2;
			else {
				puts("NO");
				continue;
			}
			printf("YES %d\n", cnt);
		}
	}
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<vector>

using namespace std;

typedef long long ll;

ll n, k, a[100];

int main(){
    int T;
    scanf("%d", &T);
    ll sum = 1;
    a[1] = 1;
    for (int i = 2; i <= 31; i++){
        a[i] = a[i-1]+sum*4;
        sum *= 4;
    }
    while (T--){
        cin>>n>>k;
        if (n <= 31){
            bool flag = false;
            if (a[n] < k){
                puts("NO");
                continue;
            }
            ll t = 1, add = 1, cnt = 0;
            for (int i = 0; ; i++){
                t = t*2+1;
                cnt++;
                if (cnt > n || t*2+1 > k)
                    break;
            }
            printf("YES %lld\n", n-cnt);
        }
        else puts("YES 1");
    }
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<vector>

using namespace std;

typedef long long ll;

ll n, k, a[100];

int main(){
    int T;
    scanf("%d", &T);
    ll sum = 1;
    a[1] = 1;
    for (int i = 2; i <= 31; i++){
        a[i] = a[i-1]+sum*4;
        sum *= 4;
    }
    while (T--){
        cin>>n>>k;
        if (n <= 31){
            bool flag = false;
            if (a[n] < k || (n == 2 && k == 3)){
                puts("NO");
                continue;
            }
            ll t = 1, add = 1, cnt = 0;
            for (int i = 0; i < n; i++){
                t = t+add*2+1;
                add = add*2+1;
                cnt++;
                if (t > k) break;
            }
            printf("YES %lld\n", n-cnt);
        }
        else printf("YES %lld\n", n-1);
    }
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<vector>

using namespace std;

typedef long long ll;

ll n, k, a[100];

int main(){
    int T;
    scanf("%d", &T);
    ll sum = 1;
    a[1] = 1;
    for (int i = 2; i <= 31; i++){
        a[i] = a[i-1]+sum*4;
        sum *= 4;
    }
    while (T--){
        cin>>n>>k;
        if (n <= 31){
            bool flag = false;
            if (a[n] < k){
                puts("NO");
                continue;
            }
            ll t = 1, add = 1, cnt = 0;
            for (int i = 0; ; i++){
                t = t*2+1;
                cnt++;
                if (cnt >= n || t*2+1 > k)
                    break;
            }
            printf("YES %lld\n", n-cnt);
        }
        else printf("YES %lld\n", n-1);
    }
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

long long ha(int n) {
    if (n >= 20) return 1LL<<40;
    if (n == 0) return 0;
    return ha(n-1) * 4 + 1;
}

int main () {
    int casnum; cin >> casnum;
    while (casnum --) {
        int n, k;
        cin >> n >> k;
        int a = n-1; k--;
        long long numofa = 3, backup = 0;
        bool ok = false;
        while (true) {
            long long lasts = ha(a);
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            lasts *= numofa - 2;
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            k -= lasts;//7
            backup += lasts;
            if (backup + k < numofa) {
                break;
            }
            a--;
            if (a < 0) break;
            k -= numofa; //3
            numofa = numofa * 2 + 1;
            if (k <= 0) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
        }
        //cout << k << endl;
        if(!ok) puts("NO");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

// 1 5 13

int main () {
    int casnum; cin >> casnum;
    while (casnum --) {
        int n, k;
        cin >> n >> k;
        int a = n-1; k--;
        long long numofa = 3;
        bool ok = false;
        while (true) {
            long long lasts = (a+1)*(a+1);
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            lasts *= numofa - 2;
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            k -= lasts;
            if (lasts < numofa && k < numofa) {
                break;
            }
            k -= numofa;
            a--; numofa = numofa * 2 - 1;
            if (a < 0) break;
            if (k <= 0) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
        }
        if(!ok) puts("NO");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

long long ha(int n) {
    if (n >= 20) return 1LL<<40;
    if (n == 0) return 0;
    return ha(n-1) * 4 + 1;
}

int main () {
    int casnum; cin >> casnum;
    while (casnum --) {
        int n, k;
        cin >> n >> k;
        int a = n-1; k--;
        long long numofa = 3;
        bool ok = false;
        while (true) {
            long long lasts = ha(a);
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            lasts *= numofa - 2;
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            k -= lasts;//7
            if (lasts < numofa && k < numofa) {
                break;
            }
            a--;
            if (a < 0) break;
            k -= numofa; //3
            numofa = numofa * 2 - 1;
            if (k <= 0) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
        }
        if(!ok) puts("NO");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int HN = 100;
long long ha_arr[HN];

int main () {
    for (int i = 1; i < HN; ++ i) {
        ha_arr[i] = ha_arr[i-1] * 4 + 1;
        //cout << i << " " << ha_arr[i] << endl;
    }

    int casnum; cin >> casnum;
    while (casnum --) {
        long long n, k;
        cin >> n >> k;
        long long a = n-1; k--;
        long long numofa = 3, backup = 0;
        bool ok = false;
        while (true) {
            int ha_index = (int)a;
            if (ha_index >= HN) ha_index = HN - 1;
            long long lasts = (numofa - 2) * ha_arr[ha_index];
            if (lasts >= k) {
                ok = true;
                printf("YES %lld\n", a);
                break;
            }
            k -= lasts;//7
            backup += lasts;
            if (backup + k < numofa) {
                break;
            }
            a--;
            if (a < 0) break;
            k -= numofa; //3
            numofa = numofa * 2 + 1;
            if (k <= 0) {
                ok = true;
                printf("YES %lld\n", a);
                break;
            }
        }
        //cout << k << endl;
        if(!ok) puts("NO");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int HN = 100;
long long ha_arr[HN];

int main () {
    for (int i = 1; i < HN; ++ i) {
        ha_arr[i] = ha_arr[i-1] * 4 + 1;
        //cout << i << " " << ha_arr[i] << endl;
    }

    int casnum; cin >> casnum;
    while (casnum --) {
        long long n, k;
        cin >> n >> k;
        long long a = n-1; k--;
        long long numofa = 3, backup = 0;
        bool ok = false;
        while (true) {
            int ha_index = (int)a;
            if (ha_index >= HN) ha_index = HN - 1;
            long long lasts = (numofa - 2) * ha_arr[a];
            if (lasts >= k) {
                ok = true;
                printf("YES %lld\n", a);
                break;
            }
            k -= lasts;//7
            backup += lasts;
            if (backup + k < numofa) {
                break;
            }
            a--;
            if (a < 0) break;
            k -= numofa; //3
            numofa = numofa * 2 + 1;
            if (k <= 0) {
                ok = true;
                printf("YES %lld\n", a);
                break;
            }
        }
        //cout << k << endl;
        if(!ok) puts("NO");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

long long ha(int n) {
    if (n >= 20) return 1LL<<40;
    if (n == 0) return 0;
    return ha(n-1) * 4 + 1;
}

int main () {
    int casnum; cin >> casnum;
    while (casnum --) {
        int n, k;
        cin >> n >> k;
        int a = n-1; k--;
        long long numofa = 3;
        bool ok = false;
        while (true) {
            long long lasts = ha(a);
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            lasts *= numofa - 2;
            if (lasts >= k) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
            k -= lasts;//7
            if (lasts + k < numofa) {
                break;
            }
            a--;
            if (a < 0) break;
            k -= numofa; //3
            numofa = numofa * 2 - 1;
            if (k <= 0) {
                ok = true;
                printf("YES %d\n", a);
                break;
            }
        }
        if(!ok) puts("NO");
    }
    return 0;
}


/*input
19
1 2
2 1
2 2
2 3
2 4
2 5
2 6
1 1000000000000000000
1000000000 1000000000000000000
64 64
64 3
4 4
2 100
3 6
3 7
4 10000
4 100000
4 71
4 70

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n;
	lld k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 and tot<k)
	{
		if((tot+((1LL<<i)-1))>k)
		{
			break;
		}
		tot+=((1LL<<i)-1);
		a--;
		i++;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	lld p=(1LL<<i)-1;
	if(a>0 && (val-tot-p)>= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << " " << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
3
1 1
2 2
2 12

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n,k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 && tot<k)
	{
		if((tot+((1<<i)-1))>k)
		{
			break;
		}
		tot+=((1<<i)-1);
		a--;
		i++;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val+=t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	if(a>0 && val-tot-(1<<i)+1 >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || !a))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
3
1 1
2 2
2 12

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n,k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 && tot<k)
	{
		if(tot+(1<<(i)-1)>k)
		{
			break;
		}
		tot+=((1<<i)-1);
		a--;
		i++;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val+=t;
		if(val>1e18)
			break;
		t*=4;
	}
	if((val-tot)>=rem)
	{
		cout <<"yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
19
1 2
2 1
2 2
2 3
2 4
2 5
2 6
1 1000000000000000000
1000000000 1000000000000000000
64 64
64 3
4 4
2 100
3 6
3 7
4 10000
4 100000
4 71
4 70

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	int n;
	lld k;
	cin >> n >> k ;
	int a=n;
	int i=1;
	lld tot=0;
	while (a>0 && tot<k)
	{
		if((tot+((1ll<<i)-1))>k)
		{
			break;
		}
		tot+=((1ll<<i)-1);
		a--;
		i++;
	}
	lld rem=k-tot;
	lld val=0;
	int t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	int flag=0;
	lld p=(1ll<<i)-1;
	if(a>0 && (val-tot-p)>= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << " " << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
3
1 1
2 2
2 12

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	int n,k;
	cin >> n >> k ;
	int a=n;
	int i=1;
	int tot=0;
	while (a>0 && tot<k)
	{
		if((tot+((1<<i)-1))>k)
		{
			break;
		}
		tot+=((1<<i)-1);
		a--;
		i++;
	}
	int rem=k-tot;
	int val=0;
	int t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	int flag=0;
	if(a>0 && val-tot-(1<<i)+1 >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || !a))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n;
	lld k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 and tot<k)
	{
		if((tot+((1LL<<i)-1))>k)
		{
			break;
		}
		tot+=((1LL<<i)-1);
		a--;
		++i;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	lld p=(1LL<<i)-1;
	if(a>0 && (val-tot-(1LL<<i)+1) >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
19
1 2
2 1
2 2
2 3
2 4
2 5
2 6
1 1000000000000000000
1000000000 1000000000000000000
64 64
64 3
4 4
2 100
3 6
3 7
4 10000
4 100000
4 71
4 70

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n;
	lld k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 and tot<k)
	{
		if((tot+((1LL<<i)-1))>k)
		{
			break;
		}
		tot+=((1LL<<i)-1);
		a--;
		++i;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	lld p=(1LL<<i)-1;
	if(a>0 && (val-tot-(1<<i)+1) >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << " " << a << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n;
	lld k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 and tot<k)
	{
		if((tot+((1LL<<i)-1))>k)
		{
			break;
		}
		tot+=((1LL<<i)-1);
		a--;
		++i;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	lld p=(1LL<<i)-1;
	if(a>0 && (val-tot-(1<<i)+1) >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(int i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  1000005
inline void solve()
{
	lld n;
	lld k;
	cin >> n >> k ;
	lld a=n;
	lld i=1;
	lld tot=0;
	while (a>0 and tot<k)
	{
		if((tot+((1LL<<i)-1))>k)
		{
			break;
		}
		tot+=((1LL<<i)-1);
		a--;
		++i;
	}
	lld rem=k-tot;
	lld val=0;
	lld t=1;
	rep(j,0,n)
	{
		val=val+t;
		if(val>1e18)
			break;
		t*=4;
	}
	lld flag=0;
	lld p=(1LL<<i)-1;
	if(a>0 && (val-tot-(1LL<<i)+1) >= rem)
	{
		flag=1;
	}
	if((val-tot)>=rem && (flag || a==0))
	{
		cout << "yes" <<  " " << a << endl;
	}
	else
	{
		cout <<"no" << " " << a << endl ;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	cin>>tests;
	while(tests--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_pow(ll a,ll n){
	ll ans=1;
	while(n){
		a*=a;
		if(n&1) ans*=a;
		n>>=1;
	}
	return ans;
}
ll a[100];
ll b[100];
int main(){
	a[0]=0;
	b[0]=1;
	for(int i=1;i<=40;i++){
		a[i]=a[i-1]*4+1;
		b[i]=b[i-1]*2+3;
	}
	int t;
	cin>>t;
	while(t--){
		ll n,k;
		cin>>n>>k;
		if(n<(log(3*k+1)/log(4))){
			puts("NO");
			continue;
		}
		bool fl=0;
		for(int i=0;i<=40;i++){
			if(n-i-1<0){
				fl=1;
				break;
			}
			k-=b[i]*(a[n-i-1]+1);
			//cout<<a[n-i-1]<<endl;
			if(k<=0){
				cout<<"YES"<<" "<<n-i-1<<endl;
				break;
			}
		}
		if(fl) puts("NO");
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100;
ll fac[N];
int main()
{
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=fac[i-1]*4;
	}
	int t,i,j;
	long long n,k;
	cin>>t;
	while (t--)
	{
		cin>>n>>k;
		int f=1;
		long long x=1;
		long long s;
		/*for (i=1;i<=min(n,(long long)31);i++)
		{
			x=x*4;
		}*/
		x=fac[min(n,(long long)31)];
		s=(x-1)/3;
		if (k>s) f=0;
		if (!f||(n==2&&k==3))
		{
			cout<<"NO\n";
			continue;
		}
		ll tmp=2;
		for (i=1;i<=n;i++)
		{
			tmp=tmp*2;
			s=tmp-2-i;
			if (s>k) break;
		}
		cout<<"YES "<<n-i+1<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

int n, ptl, pfl;
ll k;
ll pt[100], pf[100];

ll cnt_empty(int x) {
  return x <= pfl ? pf[x] : pf[pfl];
}

void solve() {
  scanf("%d%lld", &n, &k);
  if (cnt_empty(n - 1) >= k - 1) {
    printf("YES %d\n", n - 1);
    return;
  }
  ll ff = cnt_empty(n - 1);
  ll x = 5;
  for (int i = 2; i <= n && pt[i] <= k; i++) {
    ff += x * cnt_empty(n - i);
    if (ff >= k - pt[i - 1]) {
      printf("YES %d\n", n - i);
      return;
    }
    x = x * 2 + 3;
  }
  puts("NO");
}

int main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

  ll kmax = ll(1e18);

  for (ptl = 1; ; ptl++) {
    pt[ptl] = pt[ptl - 1] * 2 + 1;
    if (pt[ptl] > kmax) {
      break;
    }
  }

  for (pfl = 1; ; pfl++) {
    pf[pfl] = pf[pfl - 1] + (1LL << (pfl + pfl - 2));
//    cout << pfl << " : " << pf[pfl] << "\n";
    if (pf[pfl] > kmax) {
      break;
    }
  }

  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = int(1e5 + 5);
const int mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

int n, lim, lime, ansi;
bool f = false;
ll k;
ll p[100], e[100];

ll get_e(int x) {
  return x <= lime ? e[x] : e[lime];
}

ll calc(int x, int y) {
  if (x == y) {
    return 0LL;
  }
  ll ret = get_e(x - 1) * 2 - x + y;
  if (ret >= k) {
    f = true;
  } else {
    ret += calc(x - 1, y) * 2;
    if (ret >= k) {
      f = true;
    }
  }
  return ret;
}

void solve() {
  scanf("%d%lld", &n, &k);
  for (int i = lim; i >= 0; i--) {
    if (k >= p[i]) {
      k -= p[i];
      ansi = n - i;
      break;
    }
  }
  f = false;
  if (calc(n, ansi) >= k || f || k == 0) {
    printf("YES %d\n", ansi);
  } else {
    puts("NO");
  }
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  ll maxk = ll(1e18);
  for (int i = 1; ; i++) {
    p[i] = p[i - 1] + (1LL << i) - 1;
    if (p[i] > maxk) {
      lim = i - 1;
      break;
    }
  }
  for (int i = 1; ; i++) {
    e[i] = e[i - 1] * 4 + 1;
    if (e[i] > maxk) {
      lime = i - 1;
      break;
    }
  }
  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

int n, ptl, pfl;
ll k;
ll pt[100], pf[100];

ll cnt_empty(int x) {
  return x <= pfl ? pf[x] : pf[pfl];
}

void solve() {
  scanf("%d%lld", &n, &k);
  if (cnt_empty(n - 1) >= k - 1) {
    printf("YES %d\n", n - 1);
    return;
  }
  ll ff = cnt_empty(n - 1);
  ll x = 5;
  for (int i = 2; i <= n && pt[i] <= k; i++) {
    ff += x * cnt_empty(n - i);
    if (ff >= k - pt[i]) {
      printf("YES %d\n", n - i);
    }
    x = x * 2 + 3;
  }
  puts("NO");
}

int main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

  ll kmax = ll(1e18);

  for (ptl = 1; ; ptl++) {
    pt[ptl] = pt[ptl - 1] * 2 + 1;
    if (pt[ptl] > kmax) {
      break;
    }
  }

  for (pfl = 1; ; pfl++) {
    pf[pfl] = pf[pfl - 1] + (1LL << (pfl + pfl - 2));
//    cout << pfl << " : " << pf[pfl] << "\n";
    if (pf[pfl] > kmax) {
      break;
    }
  }

  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

ll n, lim, lime, ansi;
bool f = false;
ll k;
ll p[100], e[100];

ll get_e(ll x) {
  return x <= lime ? e[x] : e[lime];
}

ll calc(ll x, ll y) {
  if (x == y) {
    return 0LL;
  }
  ll ret = get_e(x - 1) * 2 - x + y;
  if (ret >= k) {
    f = true;
  } else {
    ret += calc(x - 1, y) * 2;
    if (ret >= k) {
      f = true;
    }
  }
  return ret;
}

void solve() {
  scanf("%lld%lld", &n, &k);
  for (ll i = lim; i >= 0; i--) {
    if (k >= p[i] && n >= i) {
      k -= p[i];
      ansi = n - i;
      break;
    }
  }
  f = false;
  if (calc(n, ansi) >= k || f || k == 0) {
    printf("YES %lld\n", ansi);
  } else {
    puts("NO");
  }
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  ll maxk = ll(1e18);
  for (ll i = 1; ; i++) {
    p[i] = p[i - 1] + (1LL << i) - 1;
    if (p[i] > maxk) {
      lim = i;
      break;
    }
  }
  for (ll i = 1; ; i++) {
    e[i] = e[i - 1] * 4 + 1;
    if (e[i] > maxk) {
      lime = i;
      break;
    }
  }
  ll tests = 1;
  scanf("%lld", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

ll n, lim, lime, ansi;
bool f = false;
ll k;
ll p[100], e[100];

ll get_e(ll x) {
  return x <= lime ? e[x] : e[lime];
}

ll calc(ll x, ll y) {
  if (x == y) {
    return 0LL;
  }
  ll ret = get_e(x - 1) * 2 - x + y;
  if (ret >= k) {
    f = true;
  } else {
    ret += calc(x - 1, y) * 2;
    if (ret >= k) {
      f = true;
    }
  }
  return ret;
}

void solve() {
  scanf("%lld%lld", &n, &k);
  if (get_e(n - 1) >= k) {
    puts("YES 1");
    return;
  }
  for (ll i = lim; i >= 0; i--) {
    if (k >= p[i] && n >= i) {
//      cout << k << " " << p[i] << " " << i << "\n";
      k -= p[i];
      ansi = n - i;
      break;
    }
  }
  f = false;
  if (calc(n, ansi) >= k || f || k == 0) {
    printf("YES %lld\n", ansi);
  } else {
    puts("NO");
  }
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  ll maxk = ll(1e18);
  for (ll i = 1; ; i++) {
    p[i] = p[i - 1] + (1LL << i) - 1;
    if (p[i] > maxk) {
      lim = i;
      break;
    }
  }
  for (ll i = 1; ; i++) {
    e[i] = e[i - 1] * 4 + 1;
    if (e[i] > maxk) {
      lime = i;
      break;
    }
  }
  ll tests = 1;
  scanf("%lld", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = int(1e5 + 5);
const int mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

int n, lim, lime, ansi;
bool f = false;
ll k;
ll p[100], e[100];

ll get_e(int x) {
  return x <= lime ? e[x] : e[lime];
}

ll calc(int x, int y) {
  if (x == y) {
    return 0LL;
  }
  ll ret = get_e(x - 1) * 2 - x + y;
  if (ret >= k) {
    f = true;
  } else {
    ret += calc(x - 1, y) * 2;
    if (ret >= k) {
      f = true;
    }
  }
  return ret;
}

void solve() {
  scanf("%d%lld", &n, &k);
  for (int i = lim; i >= 0; i--) {
    if (k >= p[i]) {
      k -= p[i];
      ansi = n - i;
      break;
    }
  }
  f = false;
  if (calc(n, ansi) >= k || f || k == 0) {
    printf("YES %d\n", ansi);
  } else {
    puts("NO");
  }
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  ll maxk = ll(1e18);
  for (int i = 1; ; i++) {
    p[i] = p[i - 1] + (1LL << i) - 1;
    if (p[i] > maxk) {
      lim = i;
      break;
    }
  }
  for (int i = 1; ; i++) {
    e[i] = e[i - 1] * 4 + 1;
    if (e[i] > maxk) {
      lime = i;
      break;
    }
  }
  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

int n, ptl, pfl;
ll k;
ll pt[100], pf[100];

ll cnt_empty(int x) {
  return x <= pfl ? pf[x] : pf[pfl];
}

void solve() {
  scanf("%d%lld", &n, &k);
  if (cnt_empty(n - 1) >= k - 1) {
    printf("YES %d\n", n - 1);
    return;
  }
  ll ff = cnt_empty(n - 1);
  ll x = 5;
  for (int i = 2; i <= n && pt[i] <= k; i++) {
    ff += x * cnt_empty(n - i);
//    cout << ff << " " << k << " " << pt[i] << "\n";
    if (ff >= k - pt[i]) {
      printf("YES %d\n", n - i);
      return;
    }
    x = x * 2 + 3;
  }
  puts("NO");
}

int main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

  ll kmax = ll(1e18);

  for (ptl = 1; ; ptl++) {
    pt[ptl] = pt[ptl - 1] + (1LL << ptl) - 1;
    if (pt[ptl] > kmax) {
      break;
    }
  }

  for (pfl = 1; ; pfl++) {
    pf[pfl] = pf[pfl - 1] + (1LL << (pfl + pfl - 2));
//    cout << pfl << " : " << pf[pfl] << "\n";
    if (pf[pfl] > kmax) {
      break;
    }
  }

  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = int(1e5 + 5);
const ll mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

ll n, lim, lime, ansi;
bool f = false;
ll k;
ll p[100], e[100];

ll get_e(ll x) {
  return x <= lime ? e[x] : e[lime];
}

ll calc(ll x, ll y) {
  if (x == y) {
    return 0LL;
  }
  ll ret = get_e(x - 1) * 2 - x + y;
  if (ret >= k) {
    f = true;
  } else {
    ret += calc(x - 1, y) * 2;
    if (ret >= k) {
      f = true;
    }
  }
  return ret;
}

void solve() {
  scanf("%lld%lld", &n, &k);
  if (get_e(n - 1) >= k) {
    printf("YES %lld\n", n - 1);
    return;
  }
  for (ll i = lim; i >= 0; i--) {
    if (k >= p[i] && n >= i) {
//      cout << k << " " << p[i] << " " << i << "\n";
      k -= p[i];
      ansi = n - i;
      break;
    }
  }
  f = false;
  if (calc(n, ansi) >= k || f || k == 0) {
    printf("YES %lld\n", ansi);
  } else {
    puts("NO");
  }
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  ll maxk = ll(1e18);
  for (ll i = 1; ; i++) {
    p[i] = p[i - 1] + (1LL << i) - 1;
    if (p[i] > maxk) {
      lim = i;
      break;
    }
  }
  for (ll i = 1; ; i++) {
    e[i] = e[i - 1] * 4 + 1;
    if (e[i] > maxk) {
      lime = i;
      break;
    }
  }
  ll tests = 1;
  scanf("%lld", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const LL inf = (1e18) + 100;

LL mul(LL a, LL b)
{
	if (a > b)
		swap(a, b);
	if (!a)
		return 0;
	if (a == 1)
		return b;

	LL tmp = mul(a / 2, b);
	if (tmp >= inf)
		return tmp;

	return tmp + tmp + (a % 2, b);
}

LL zajeb(LL ile, int n)
{
	if (ile >= inf)
		return ile;

	LL tmp = 1, s = 0;
	FORQ(i, 1, n)
	{
		if (tmp >= inf)
			return tmp;

		s += tmp;

		if (s >= inf)
			return s;

		tmp *= 4;
	}

	// zajeb wszystkie kwadraty
	return mul(ile, s);
}

int siekaj(int n, LL k)
{
	// ile kwadratow, 2^x
	int x = 0;
	while (n && k > 0)
	{
		// sieknij
		LL ile = 1;
		FORQ(i, 1, x)
		{
			ile *= 2;
			if (ile >= inf)
				break;
		}

		// trzeba sieknac brzeg - kazdy kwadrat 1 raz
		LL iles = 2 * (ile - 1) + 1;
		if (k < iles)
			return -1;
		k -= iles;

		// zwieksza sie liczba kwadratow na brzegu i zmniejsza ich rozmiar
		x++;
		n--;

		if (k <= 0)
			break;

		// dobij wszystkie kwadraty spoza
		k -= zajeb(4 * (ile - 1) + 1, n);
	}

	if (k > 0)
		return -1;

	return n;
}

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

	REP(c, t)
	{
		int n;
		LL k;

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

		int res = siekaj(n, k);
		if (res == -1)
			printf("NO\n");
		else
			printf("YES %d\n", res);
	}

	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const LL inf = (1e18) + 100;

LL mul(LL a, LL b)
{
	if (a > b)
		swap(a, b);
	if (!a)
		return 0;
	if (a == 1)
		return b;

	LL tmp = mul(a / 2, b);
	if (tmp >= inf)
		return tmp;

	return tmp + tmp + (a % 2, b);
}

LL zajeb(LL ile, int n)
{
	if (ile >= inf)
		return ile;

	LL tmp = 1, s = 0;
	FORQ(i, 1, n)
	{
		if (tmp >= inf)
			return tmp;

		s += tmp;

		if (s >= inf)
			return s;

		tmp *= 4;
	}

	// zajeb wszystkie kwadraty
	return mul(ile, s);
}

int siekaj(int n, LL k)
{
	// ile kwadratow, 2^x
	int x = 0;
	// ile siekniec opcjonalnych
	LL done = 0;
	while (n && k > 0)
	{
		// sieknij
		LL ile = 1;
		FORQ(i, 1, x)
		{
			ile *= 2;
			if (ile >= inf)
				break;
		}

		// trzeba sieknac brzeg - kazdy kwadrat 1 raz
		LL iles = 2 * (ile - 1) + 1;
		if (k + done < iles)
			return -1;

		k -= iles;

		// zwieksza sie liczba kwadratow na brzegu i zmniejsza ich rozmiar
		x++;
		n--;

		if (k <= 0)
			break;

		// dobij wszystkie kwadraty spoza
		LL pom = zajeb(4 * (ile - 1) + 1, n);
		k -= pom;
		done += pom;
	}

	if (k > 0)
		return -1;

	return n;
}

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

	REP(c, t)
	{
		int n;
		LL k;

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

		int res = siekaj(n, k);
		if (res == -1)
			printf("NO\n");
		else
			printf("YES %d\n", res);
	}

	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const LL inf = (1e18) + 100;

LL mul(LL a, LL b)
{
	if (a > b)
		swap(a, b);
	if (!a)
		return 0;
	if (a == 1)
		return b;

	LL tmp = mul(a / 2, b);
	if (tmp >= inf)
		return tmp;

	return tmp + tmp + mul(a % 2, b);
}

LL zajeb(LL ile, int n)
{
	if (ile >= inf)
		return ile;

	LL tmp = 1, s = 0;
	FORQ(i, 1, n)
	{
		if (tmp >= inf)
			return tmp;

		s += tmp;

		if (s >= inf)
			return s;

		tmp *= 4;
	}

	// zajeb wszystkie kwadraty
	return mul(ile, s);
}

int siekaj(int n, LL k)
{
	// ile kwadratow, 2^x
	int x = 0;
	// ile siekniec opcjonalnych
	LL done = 0;
	while (n && k > 0)
	{
		// sieknij
		LL ile = 1;
		FORQ(i, 1, x)
		{
			ile *= 2;
			if (ile >= inf)
				break;
		}

		// trzeba sieknac brzeg - kazdy kwadrat 1 raz
		LL iles = 2 * (ile - 1) + 1;
		if (k + done < iles)
			return -1;

		k -= iles;

		// zwieksza sie liczba kwadratow na brzegu i zmniejsza ich rozmiar
		x++;
		n--;

		if (k <= 0)
			break;

		// dobij wszystkie kwadraty spoza
		LL pom = zajeb(4 * (ile - 1) + 1, n);
		k -= pom;
		done += pom;
	}

	if (k > 0)
		return -1;

	return n;
}

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

	REP(c, t)
	{
		int n;
		LL k;

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

		int res = siekaj(n, k);
		if (res == -1)
			printf("NO\n");
		else
			printf("YES %d\n", res);
	}

	return 0;
}