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

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

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

k.z = i
h.p = k
h.v = b
i.z = b
n.z = b
m.p = i
m.v = k
b.z = n
assert i.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.p: A = None
        self.v: A = None
        self.txt = txt

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

k.z = i
h.p = k
h.v = b
i.z = b
n.z = b
m.p = i
m.v = k
b.z = n
assert i.z.z.z.z.txt == "n"