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

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

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

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

a = A("a")
b = B("b")
i = C("i")
n = D("n")
h = A("h")
j = C("j")
c = B("c")
d = C("d")
f = C("f")

a.z = b
a.y = n
a.p = h
b.w = d
b.t = d
b.r = h
b.v = j
i.r = b
i.x = h
i.w = f
n.s = c
h.z = b
h.y = n
h.p = a
j.r = c
j.x = a
j.w = i
c.w = f
c.r = a
c.t = i
c.v = j
d.r = b
d.x = a
d.w = f
f.r = b
f.x = a
f.w = d
assert d.w.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.y: D = None
        self.p: A = None
        self.txt = txt

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

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

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

a = A("a")
b = B("b")
i = C("i")
n = D("n")
h = A("h")
j = C("j")
c = B("c")
d = C("d")
f = C("f")

a.z = b
a.y = n
a.p = h
b.w = d
b.t = d
b.r = h
b.v = j
i.r = b
i.x = h
i.w = f
n.s = c
h.z = b
h.y = n
h.p = a
j.r = c
j.x = a
j.w = i
c.w = f
c.r = a
c.t = i
c.v = j
d.r = b
d.x = a
d.w = f
f.r = b
f.x = a
f.w = d
assert d.w.r.r.txt == "h"