class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

g = A("g")
n = B("n")
b = B("b")

g.y = n
n.s = b
n.y = b
b.s = n
b.y = n
assert g.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

g = A("g")
n = B("n")
b = B("b")

g.y = n
n.s = b
n.y = b
b.s = n
b.y = n
assert g.y.y.y.txt == "n"