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

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

i = A("i")
j = B("j")
d = B("d")
a = B("a")
h = B("h")
b = A("b")

i.u = j
j.y = b
d.y = b
a.y = i
h.y = i
b.u = h
assert b.u.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

i = A("i")
j = B("j")
d = B("d")
a = B("a")
h = B("h")
b = A("b")

i.u = j
j.y = b
d.y = b
a.y = i
h.y = i
b.u = h
assert b.u.y.u.txt == "j"