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

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

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

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

h.w = m
h.x = g
m.r = d
m.t = k
m.o = h
d.w = m
g.w = m
k.r = g
k.t = m
k.o = h
assert d.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.x: C = None
        self.txt = txt

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

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

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

h.w = m
h.x = g
m.r = d
m.t = k
m.o = h
d.w = m
g.w = m
k.r = g
k.t = m
k.o = h
assert d.w.r.w.txt == "m"