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

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

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

n = A("n")
c = B("c")
l = C("l")
h = A("h")

n.x = h
n.o = l
c.q = h
c.z = l
c.y = l
l.s = c
l.p = c
h.x = n
h.o = l
assert c.q.o.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.o: C = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
l = C("l")
h = A("h")

n.x = h
n.o = l
c.q = h
c.z = l
c.y = l
l.s = c
l.p = c
h.x = n
h.o = l
assert c.q.o.s.z.txt == "l"