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

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

j = A("j")
b = B("b")
n = A("n")
k = B("k")
h = A("h")

j.t = h
j.p = n
b.v = h
b.z = k
n.t = h
n.p = h
k.v = n
k.z = b
h.t = n
h.p = j
assert k.z.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
b = B("b")
n = A("n")
k = B("k")
h = A("h")

j.t = h
j.p = n
b.v = h
b.z = k
n.t = h
n.p = h
k.v = n
k.z = b
h.t = n
h.p = j
assert k.z.v.t.txt == "n"