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

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

m = A("m")
i = B("i")
j = B("j")
d = B("d")

m.q = j
m.t = d
i.p = m
i.z = m
j.p = m
j.z = m
d.p = m
d.z = m
assert m.q.p.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
j = B("j")
d = B("d")

m.q = j
m.t = d
i.p = m
i.z = m
j.p = m
j.z = m
d.p = m
d.z = m
assert m.q.p.t.z.txt == "m"