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

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

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

h = A("h")
g = B("g")
b = C("b")
i = B("i")
e = C("e")
d = B("d")
k = A("k")

h.o = k
g.t = e
g.x = i
b.w = e
i.t = b
i.x = g
e.w = b
d.t = b
d.x = g
k.o = h
assert i.x.t.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

h = A("h")
g = B("g")
b = C("b")
i = B("i")
e = C("e")
d = B("d")
k = A("k")

h.o = k
g.t = e
g.x = i
b.w = e
i.t = b
i.x = g
e.w = b
d.t = b
d.x = g
k.o = h
assert i.x.t.w.w.w.txt == "b"