class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.r: C = None
        self.w: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: D = None
        self.t: D = None
        self.txt = txt

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

m = A("m")
b = B("b")
a = C("a")
j = D("j")

m.z = a
m.r = a
m.w = j
b.p = m
b.u = m
b.y = j
a.x = j
a.t = j
j.q = m
assert a.t.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.r: C = None
        self.w: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: D = None
        self.t: D = None
        self.txt = txt

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

m = A("m")
b = B("b")
a = C("a")
j = D("j")

m.z = a
m.r = a
m.w = j
b.p = m
b.u = m
b.y = j
a.x = j
a.t = j
j.q = m
assert a.t.q.r.txt == "a"