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

class B:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: B = None
        self.txt = txt

i = A("i")
d = B("d")
c = B("c")

i.q = d
i.o = c
d.x = c
d.y = c
c.x = d
c.y = d
assert d.x.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: B = None
        self.txt = txt

i = A("i")
d = B("d")
c = B("c")

i.q = d
i.o = c
d.x = c
d.y = c
c.x = d
c.y = d
assert d.x.x.y.txt == "c"