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

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

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

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

d = A("d")
b = B("b")
m = C("m")
h = D("h")

d.t = h
d.z = m
d.r = b
b.z = m
b.q = h
b.w = d
m.t = d
h.q = b
h.w = d
h.r = d
h.t = d
assert m.t.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.z: C = None
        self.r: B = None
        self.txt = txt

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

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

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

d = A("d")
b = B("b")
m = C("m")
h = D("h")

d.t = h
d.z = m
d.r = b
b.z = m
b.q = h
b.w = d
m.t = d
h.q = b
h.w = d
h.r = d
h.t = d
assert m.t.t.w.txt == "d"