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

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

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

a = A("a")
b = B("b")
f = C("f")

a.y = f
b.y = f
b.t = a
f.p = a
assert f.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

a = A("a")
b = B("b")
f = C("f")

a.y = f
b.y = f
b.t = a
f.p = a
assert f.p.y.p.txt == "a"