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

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

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

m = A("m")
f = B("f")
k = C("k")
h = A("h")
a = B("a")
j = B("j")

m.w = h
f.r = k
k.s = h
k.w = j
h.w = m
a.r = k
j.r = k
assert f.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
k = C("k")
h = A("h")
a = B("a")
j = B("j")

m.w = h
f.r = k
k.s = h
k.w = j
h.w = m
a.r = k
j.r = k
assert f.r.w.r.txt == "k"