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

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

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

h = A("h")
k = B("k")
g = C("g")
m = C("m")
f = A("f")

h.o = m
h.y = g
k.o = f
k.v = m
g.x = k
g.s = k
g.w = m
m.x = k
m.s = k
m.w = g
f.o = g
f.y = g
assert f.y.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
g = C("g")
m = C("m")
f = A("f")

h.o = m
h.y = g
k.o = f
k.v = m
g.x = k
g.s = k
g.w = m
m.x = k
m.s = k
m.w = g
f.o = g
f.y = g
assert f.y.w.w.txt == "g"