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

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

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

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

m = A("m")
k = B("k")
f = C("f")
e = D("e")

m.t = k
m.y = k
m.x = k
m.w = e
k.t = f
k.x = m
f.q = k
e.x = k
assert m.t.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: B = None
        self.w: D = None
        self.x: B = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
f = C("f")
e = D("e")

m.t = k
m.y = k
m.x = k
m.w = e
k.t = f
k.x = m
f.q = k
e.x = k
assert m.t.t.q.t.txt == "f"