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

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

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

f = A("f")
g = B("g")
c = C("c")
a = A("a")

f.y = a
f.p = a
g.p = a
g.q = a
g.r = c
c.z = g
c.w = g
a.y = f
a.p = f
assert f.p.p.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: A = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
c = C("c")
a = A("a")

f.y = a
f.p = a
g.p = a
g.q = a
g.r = c
c.z = g
c.w = g
a.y = f
a.p = f
assert f.p.p.p.y.txt == "f"