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

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

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

h = A("h")
d = B("d")
k = C("k")
f = C("f")

h.s = d
d.x = h
d.s = h
k.w = f
f.w = k
assert f.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
k = C("k")
f = C("f")

h.s = d
d.x = h
d.s = h
k.w = f
f.w = k
assert f.w.w.w.w.txt == "f"