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

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

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

m = A("m")
f = B("f")
i = C("i")
b = C("b")
j = A("j")

m.y = f
f.y = b
f.w = m
i.r = f
b.r = f
j.y = f
assert j.y.y.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
i = C("i")
b = C("b")
j = A("j")

m.y = f
f.y = b
f.w = m
i.r = f
b.r = f
j.y = f
assert j.y.y.r.w.txt == "m"