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

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

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

k = A("k")
c = B("c")
a = C("a")
b = A("b")
l = B("l")

k.q = b
c.t = a
c.o = a
c.u = b
a.s = b
a.p = c
a.y = k
b.q = k
l.t = a
l.o = a
l.u = b
assert a.s.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
a = C("a")
b = A("b")
l = B("l")

k.q = b
c.t = a
c.o = a
c.u = b
a.s = b
a.p = c
a.y = k
b.q = k
l.t = a
l.o = a
l.u = b
assert a.s.q.q.q.q.txt == "b"