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

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

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

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

d = A("d")
j = B("j")
m = C("m")
n = D("n")
c = C("c")
h = B("h")
i = B("i")
l = B("l")
g = D("g")
f = C("f")

d.z = m
j.o = g
m.z = f
m.v = d
m.r = d
n.v = c
n.y = g
c.z = m
c.v = d
c.r = d
h.o = n
i.o = g
l.o = n
g.v = m
g.y = n
f.z = c
f.v = d
f.r = d
assert f.z.v.z.v.z.v.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
m = C("m")
n = D("n")
c = C("c")
h = B("h")
i = B("i")
l = B("l")
g = D("g")
f = C("f")

d.z = m
j.o = g
m.z = f
m.v = d
m.r = d
n.v = c
n.y = g
c.z = m
c.v = d
c.r = d
h.o = n
i.o = g
l.o = n
g.v = m
g.y = n
f.z = c
f.v = d
f.r = d
assert f.z.v.z.v.z.v.z.r.txt == "d"