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

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

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

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

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

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

a.q = h
l.p = h
l.o = a
h.p = l
h.o = a
assert l.p.o.q.txt == "h"