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

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

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

a = A("a")
e = B("e")
n = C("n")
b = C("b")
c = A("c")
g = B("g")
i = A("i")
f = A("f")

a.u = g
a.s = n
e.q = g
e.r = n
n.q = c
b.q = f
c.u = e
c.s = b
g.q = e
g.r = n
i.u = g
i.s = n
f.u = e
f.s = b
assert c.s.q.s.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: C = None
        self.txt = txt

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

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

a = A("a")
e = B("e")
n = C("n")
b = C("b")
c = A("c")
g = B("g")
i = A("i")
f = A("f")

a.u = g
a.s = n
e.q = g
e.r = n
n.q = c
b.q = f
c.u = e
c.s = b
g.q = e
g.r = n
i.u = g
i.s = n
f.u = e
f.s = b
assert c.s.q.s.q.s.q.txt == "f"