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

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

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

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

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

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

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

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

h.o = b
b.o = g
g.q = h
g.o = h
g.p = n
n.o = g
assert h.o.o.o.o.txt == "b"