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

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

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

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

c.u = d
j.s = d
j.p = l
j.q = b
b.s = h
d.u = c
k.s = d
k.p = j
k.q = h
h.s = b
l.s = c
l.p = k
l.q = b
e.s = d
e.p = l
e.q = h
assert j.q.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

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

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

c.u = d
j.s = d
j.p = l
j.q = b
b.s = h
d.u = c
k.s = d
k.p = j
k.q = h
h.s = b
l.s = c
l.p = k
l.q = b
e.s = d
e.p = l
e.q = h
assert j.q.s.s.s.txt == "h"