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

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

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

a = A("a")
m = B("m")
g = C("g")
e = C("e")
n = A("n")
d = A("d")
f = B("f")

a.q = e
a.x = n
m.x = e
m.s = e
m.r = f
g.u = d
g.y = m
e.u = n
e.y = f
n.q = g
n.x = a
d.q = g
d.x = a
f.x = e
f.s = e
f.r = m
assert d.q.u.q.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.x: A = None
        self.txt = txt

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

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

a = A("a")
m = B("m")
g = C("g")
e = C("e")
n = A("n")
d = A("d")
f = B("f")

a.q = e
a.x = n
m.x = e
m.s = e
m.r = f
g.u = d
g.y = m
e.u = n
e.y = f
n.q = g
n.x = a
d.q = g
d.x = a
f.x = e
f.s = e
f.r = m
assert d.q.u.q.y.s.txt == "e"