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

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

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

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

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

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

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

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

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

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

j.p = h
j.z = g
g.t = h
g.w = h
i.z = h
i.u = h
i.s = h
i.r = j
h.p = i
h.r = g
assert g.t.r.w.r.txt == "g"