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

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

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

a = A("a")
h = B("h")
g = C("g")
i = B("i")

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

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

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

a = A("a")
h = B("h")
g = C("g")
i = B("i")

a.y = i
h.q = i
h.p = a
g.o = h
i.q = h
i.p = a
assert a.y.q.p.y.txt == "i"