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

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

h = A("h")
e = B("e")
d = B("d")
n = A("n")

h.u = e
e.z = h
d.z = n
n.u = d
assert n.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

h = A("h")
e = B("e")
d = B("d")
n = A("n")

h.u = e
e.z = h
d.z = n
n.u = d
assert n.u.z.u.txt == "d"