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

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

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

b = A("b")
m = B("m")
e = C("e")
g = B("g")
h = C("h")

b.o = h
b.s = h
b.u = e
m.s = b
m.q = e
e.q = b
e.x = h
g.s = b
g.q = h
h.q = b
h.x = e
assert g.q.q.s.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.s: C = None
        self.u: C = None
        self.txt = txt

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

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

b = A("b")
m = B("m")
e = C("e")
g = B("g")
h = C("h")

b.o = h
b.s = h
b.u = e
m.s = b
m.q = e
e.q = b
e.x = h
g.s = b
g.q = h
h.q = b
h.x = e
assert g.q.q.s.q.o.txt == "h"