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

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

c = A("c")
k = B("k")
m = A("m")
e = A("e")
f = B("f")
n = A("n")
h = A("h")
g = B("g")
d = B("d")
a = B("a")

c.z = h
k.z = h
k.v = c
m.z = c
e.z = n
f.z = c
f.v = e
n.z = e
h.z = e
g.z = c
g.v = m
d.z = e
d.v = c
a.z = m
a.v = h
assert h.z.z.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

c = A("c")
k = B("k")
m = A("m")
e = A("e")
f = B("f")
n = A("n")
h = A("h")
g = B("g")
d = B("d")
a = B("a")

c.z = h
k.z = h
k.v = c
m.z = c
e.z = n
f.z = c
f.v = e
n.z = e
h.z = e
g.z = c
g.v = m
d.z = e
d.v = c
a.z = m
a.v = h
assert h.z.z.z.z.z.z.z.z.z.txt == "e"