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

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

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

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

n = A("n")
k = B("k")
g = C("g")
a = D("a")
b = D("b")
i = A("i")
f = C("f")
m = B("m")
j = A("j")
h = D("h")

n.z = g
k.s = g
g.v = k
a.s = f
a.v = g
a.r = h
a.z = b
b.s = f
b.v = f
b.r = h
b.z = a
i.z = f
f.v = k
m.s = f
j.z = g
h.s = f
h.v = f
h.r = b
h.z = b
assert f.v.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

n = A("n")
k = B("k")
g = C("g")
a = D("a")
b = D("b")
i = A("i")
f = C("f")
m = B("m")
j = A("j")
h = D("h")

n.z = g
k.s = g
g.v = k
a.s = f
a.v = g
a.r = h
a.z = b
b.s = f
b.v = f
b.r = h
b.z = a
i.z = f
f.v = k
m.s = f
j.z = g
h.s = f
h.v = f
h.r = b
h.z = b
assert f.v.s.v.txt == "k"