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

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

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

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

b.o = h
g.q = h
g.x = f
f.u = g
h.q = g
h.x = f
assert h.q.x.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

b.o = h
g.q = h
g.x = f
f.u = g
h.q = g
h.x = f
assert h.q.x.u.q.txt == "h"