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

b = A("b")
h = B("h")
c = B("c")
j = A("j")

b.u = h
h.y = j
c.y = b
j.u = h
assert j.u.y.u.y.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

b = A("b")
h = B("h")
c = B("c")
j = A("j")

b.u = h
h.y = j
c.y = b
j.u = h
assert j.u.y.u.y.txt == "j"