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

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

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

f = A("f")
k = B("k")
g = C("g")
b = B("b")
h = A("h")
l = B("l")
n = C("n")

f.q = n
k.u = n
k.r = f
g.s = f
b.u = n
b.r = h
h.q = g
l.u = n
l.r = h
n.s = f
assert g.s.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
k = B("k")
g = C("g")
b = B("b")
h = A("h")
l = B("l")
n = C("n")

f.q = n
k.u = n
k.r = f
g.s = f
b.u = n
b.r = h
h.q = g
l.u = n
l.r = h
n.s = f
assert g.s.q.s.q.txt == "n"