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

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

h = A("h")
k = B("k")
m = A("m")
g = B("g")
a = B("a")
c = A("c")

h.z = c
k.w = m
k.p = a
m.z = h
g.w = c
g.p = k
a.w = h
a.p = g
c.z = m
assert c.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.w: A = None
        self.p: B = None
        self.txt = txt

h = A("h")
k = B("k")
m = A("m")
g = B("g")
a = B("a")
c = A("c")

h.z = c
k.w = m
k.p = a
m.z = h
g.w = c
g.p = k
a.w = h
a.p = g
c.z = m
assert c.z.z.z.txt == "c"