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

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

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

j = A("j")
d = B("d")
e = C("e")
m = B("m")
b = C("b")
h = C("h")
c = C("c")
l = A("l")
a = C("a")

j.s = l
j.x = d
d.y = b
d.r = m
d.x = e
e.q = j
m.y = h
m.r = d
m.x = a
b.q = j
h.q = l
c.q = j
l.s = j
l.x = m
a.q = l
assert c.q.x.r.y.q.s.x.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
e = C("e")
m = B("m")
b = C("b")
h = C("h")
c = C("c")
l = A("l")
a = C("a")

j.s = l
j.x = d
d.y = b
d.r = m
d.x = e
e.q = j
m.y = h
m.r = d
m.x = a
b.q = j
h.q = l
c.q = j
l.s = j
l.x = m
a.q = l
assert c.q.x.r.y.q.s.x.x.q.txt == "j"