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

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

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

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

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

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

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

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

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