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

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

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

f = A("f")
e = B("e")
g = C("g")
k = A("k")

f.w = e
e.p = f
g.w = f
k.w = e
assert k.w.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
g = C("g")
k = A("k")

f.w = e
e.p = f
g.w = f
k.w = e
assert k.w.p.w.p.txt == "f"