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

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

j = A("j")
m = B("m")
d = B("d")
g = B("g")
i = B("i")
e = A("e")
a = B("a")
n = B("n")

j.z = i
j.v = d
m.w = i
m.z = a
d.w = g
d.z = m
g.w = n
g.z = i
i.w = g
i.z = m
e.z = n
e.v = m
a.w = m
a.z = g
n.w = m
n.z = g
assert n.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.v: B = None
        self.txt = txt

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

j = A("j")
m = B("m")
d = B("d")
g = B("g")
i = B("i")
e = A("e")
a = B("a")
n = B("n")

j.z = i
j.v = d
m.w = i
m.z = a
d.w = g
d.z = m
g.w = n
g.z = i
i.w = g
i.z = m
e.z = n
e.v = m
a.w = m
a.z = g
n.w = m
n.z = g
assert n.z.z.z.z.z.txt == "g"