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

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

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

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

d = A("d")
m = B("m")
a = C("a")
c = D("c")

d.x = m
m.t = d
m.r = d
m.p = c
a.u = m
a.q = d
c.u = d
assert a.u.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
a = C("a")
c = D("c")

d.x = m
m.t = d
m.r = d
m.p = c
a.u = m
a.q = d
c.u = d
assert a.u.t.x.txt == "m"