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

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

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

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

d = A("d")
j = B("j")
e = C("e")
m = D("m")
c = C("c")

d.q = m
j.t = c
j.u = d
j.z = d
e.x = j
m.x = d
m.t = j
c.x = j
assert d.q.t.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
e = C("e")
m = D("m")
c = C("c")

d.q = m
j.t = c
j.u = d
j.z = d
e.x = j
m.x = d
m.t = j
c.x = j
assert d.q.t.z.q.txt == "m"