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

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

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

f = A("f")
e = B("e")
n = C("n")

f.r = e
f.w = n
e.w = f
e.q = f
n.y = f
n.r = e
assert f.w.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: C = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
n = C("n")

f.r = e
f.w = n
e.w = f
e.q = f
n.y = f
n.r = e
assert f.w.r.q.txt == "f"