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

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

l = A("l")
h = B("h")
b = A("b")
n = B("n")
j = B("j")

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

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

l = A("l")
h = B("h")
b = A("b")
n = B("n")
j = B("j")

l.u = h
l.z = b
h.o = j
h.p = l
b.u = h
b.z = l
n.o = j
n.p = b
j.o = h
j.p = b
assert l.z.u.p.txt == "l"