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

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

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

e = A("e")
j = B("j")
i = C("i")
f = B("f")
k = A("k")
a = C("a")

e.w = k
j.p = i
i.p = f
i.r = j
f.p = a
k.w = e
a.p = f
a.r = f
assert k.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

e = A("e")
j = B("j")
i = C("i")
f = B("f")
k = A("k")
a = C("a")

e.w = k
j.p = i
i.p = f
i.r = j
f.p = a
k.w = e
a.p = f
a.r = f
assert k.w.w.w.w.txt == "k"