#include <iostream>
struct A;
struct B
{
    A& ref;
    int n;
    B(A& a) : ref(a), n(1) {}
    void show() const;
};

struct A
{
    B& ref;
    int n;
    A(B& b) : ref(b), n(2) {}
    void show() const;
};

void A::show() const
{
    std::cout << "A.n is " << n
              << " A.ref.n is " << ref.n
              << " A.ref.ref.n is " << ref.ref.n
              << " A.ref.ref.ref.n is " << ref.ref.ref.n
              << '\n';
}

void B::show() const
{
    std::cout << "B.n is " << n
              << " B.ref.n is " << ref.n
              << " B.ref.ref.n is " << ref.ref.n
              << " B.ref.ref.ref.n is " << ref.ref.ref.n
              << '\n';
}

int main()
{
//    std::pair<A, B> pair(pair.second, pair.first);
    struct {B first; A second;} pair = {pair.second, pair.first};
    pair.first.show();
    pair.second.show();
}
