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

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

m = A("m")
k = B("k")
f = A("f")
i = A("i")
g = B("g")
j = A("j")
n = A("n")
a = B("a")

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

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

m = A("m")
k = B("k")
f = A("f")
i = A("i")
g = B("g")
j = A("j")
n = A("n")
a = B("a")

m.v = k
m.z = f
k.v = a
k.z = g
f.v = a
f.z = n
i.v = g
i.z = f
g.v = k
g.z = a
j.v = a
j.z = i
n.v = k
n.z = j
a.v = g
a.z = g
assert i.z.v.z.txt == "g"