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

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

l = A("l")
b = B("b")
d = A("d")

l.o = d
b.q = d
b.t = l
d.o = l
assert b.t.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
d = A("d")

l.o = d
b.q = d
b.t = l
d.o = l
assert b.t.o.o.txt == "l"