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

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

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

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

g = A("g")
i = B("i")
h = C("h")
d = D("d")

g.r = i
i.t = d
i.v = h
i.p = h
h.r = i
h.p = i
h.z = i
h.w = d
d.w = g
d.s = h
d.v = h
d.t = h
assert g.r.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

g = A("g")
i = B("i")
h = C("h")
d = D("d")

g.r = i
i.t = d
i.v = h
i.p = h
h.r = i
h.p = i
h.z = i
h.w = d
d.w = g
d.s = h
d.v = h
d.t = h
assert g.r.p.w.txt == "d"