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

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

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

l = A("l")
i = B("i")
h = C("h")

l.x = i
l.o = i
i.x = h
i.r = h
i.p = l
h.q = i
assert h.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: B = None
        self.txt = txt

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

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

l = A("l")
i = B("i")
h = C("h")

l.x = i
l.o = i
i.x = h
i.r = h
i.p = l
h.q = i
assert h.q.r.q.txt == "i"