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

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

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

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

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

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

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

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

c.q = g
g.o = c
f.p = h
h.p = f
assert g.o.q.o.q.txt == "g"