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.v: A = None
        self.x: A = None
        self.txt = txt

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

h.z = a
h.v = a
n.v = f
n.x = f
d.v = h
d.x = k
k.z = a
k.v = n
a.v = f
a.x = e
f.z = n
f.v = a
e.z = d
e.v = n
assert h.z.v.z.v.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.v: A = None
        self.x: A = None
        self.txt = txt

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

h.z = a
h.v = a
n.v = f
n.x = f
d.v = h
d.x = k
k.z = a
k.v = n
a.v = f
a.x = e
f.z = n
f.v = a
e.z = d
e.v = n
assert h.z.v.z.v.z.txt == "n"