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

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

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

f = A("f")
m = B("m")
a = C("a")
d = B("d")
g = C("g")
b = A("b")
l = A("l")
i = C("i")

f.r = i
f.s = m
f.q = b
m.s = i
a.s = b
a.r = m
d.s = a
g.s = l
g.r = d
b.r = i
b.s = d
b.q = l
l.r = g
l.s = m
l.q = f
i.s = b
i.r = d
assert l.r.r.s.s.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: B = None
        self.q: A = None
        self.txt = txt

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

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

f = A("f")
m = B("m")
a = C("a")
d = B("d")
g = C("g")
b = A("b")
l = A("l")
i = C("i")

f.r = i
f.s = m
f.q = b
m.s = i
a.s = b
a.r = m
d.s = a
g.s = l
g.r = d
b.r = i
b.s = d
b.q = l
l.r = g
l.s = m
l.q = f
i.s = b
i.r = d
assert l.r.r.s.s.q.q.txt == "f"