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

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

b = A("b")
h = B("h")
l = A("l")
a = B("a")
m = A("m")

b.o = a
h.q = b
h.z = l
l.o = a
a.q = l
a.z = b
m.o = h
assert b.o.q.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

b = A("b")
h = B("h")
l = A("l")
a = B("a")
m = A("m")

b.o = a
h.q = b
h.z = l
l.o = a
a.q = l
a.z = b
m.o = h
assert b.o.q.o.q.txt == "l"