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

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

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

j = A("j")
c = B("c")
f = C("f")
m = C("m")

j.s = c
j.w = c
c.p = f
f.r = m
m.r = f
assert j.w.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: B = None
        self.txt = txt

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

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

j = A("j")
c = B("c")
f = C("f")
m = C("m")

j.s = c
j.w = c
c.p = f
f.r = m
m.r = f
assert j.w.p.r.txt == "m"