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

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

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

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

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

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

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

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

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

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

e.w = m
e.q = m
e.z = m
e.t = j
m.p = j
j.q = e
b.u = m
b.p = e
b.x = e
assert e.t.q.w.p.txt == "j"