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

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

n = A("n")
k = B("k")
i = A("i")
c = A("c")
h = A("h")
b = B("b")
d = A("d")
m = B("m")

n.v = d
k.z = b
k.r = b
i.v = c
c.v = i
h.v = d
b.z = k
b.r = k
d.v = h
m.z = k
m.r = k
assert d.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

n = A("n")
k = B("k")
i = A("i")
c = A("c")
h = A("h")
b = B("b")
d = A("d")
m = B("m")

n.v = d
k.z = b
k.r = b
i.v = c
c.v = i
h.v = d
b.z = k
b.r = k
d.v = h
m.z = k
m.r = k
assert d.v.v.v.txt == "h"