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

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

k = A("k")
g = B("g")
i = A("i")
n = A("n")
m = A("m")
a = A("a")
f = A("f")

k.p = f
g.y = i
i.p = k
n.p = k
m.p = a
a.p = i
f.p = n
assert n.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

k = A("k")
g = B("g")
i = A("i")
n = A("n")
m = A("m")
a = A("a")
f = A("f")

k.p = f
g.y = i
i.p = k
n.p = k
m.p = a
a.p = i
f.p = n
assert n.p.p.p.txt == "n"