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

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

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

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

e.o = h
e.w = g
b.r = g
b.o = g
b.q = h
h.u = e
h.p = e
h.q = g
g.r = b
g.o = b
g.q = h
assert e.w.q.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: B = None
        self.txt = txt

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

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

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

e.o = h
e.w = g
b.r = g
b.o = g
b.q = h
h.u = e
h.p = e
h.q = g
g.r = b
g.o = b
g.q = h
assert e.w.q.u.w.txt == "g"