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

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

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

h.z = k
h.y = b
b.p = n
n.z = h
n.y = b
g.z = n
g.y = b
k.z = h
k.y = b
assert k.y.p.z.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: B = None
        self.txt = txt

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

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

h.z = k
h.y = b
b.p = n
n.z = h
n.y = b
g.z = n
g.y = b
k.z = h
k.y = b
assert k.y.p.z.y.p.txt == "n"