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

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

a = A("a")
b = B("b")
i = A("i")

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

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

a = A("a")
b = B("b")
i = A("i")

a.o = b
a.p = i
b.q = a
b.v = a
i.o = b
i.p = a
assert i.p.o.q.txt == "a"