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

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

j = A("j")
n = B("n")
h = A("h")
m = B("m")
i = B("i")

j.u = i
n.o = m
n.z = h
h.u = m
m.o = n
m.z = h
i.o = n
i.z = j
assert h.u.o.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

j = A("j")
n = B("n")
h = A("h")
m = B("m")
i = B("i")

j.u = i
n.o = m
n.z = h
h.u = m
m.o = n
m.z = h
i.o = n
i.z = j
assert h.u.o.z.u.z.txt == "h"