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

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

g = A("g")
l = B("l")
h = B("h")
b = A("b")

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

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

g = A("g")
l = B("l")
h = B("h")
b = A("b")

g.y = h
l.u = h
h.u = l
b.y = h
assert b.y.u.u.u.txt == "l"