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

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

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

h = A("h")
b = B("b")
j = C("j")
k = C("k")
g = B("g")
d = C("d")
n = B("n")
f = B("f")
m = A("m")

h.r = m
h.q = m
h.s = n
b.q = j
b.w = d
j.p = h
j.v = d
k.p = h
k.v = j
g.q = k
g.w = j
d.p = m
d.v = j
n.q = d
n.w = j
f.q = d
f.w = j
m.r = h
m.q = h
m.s = g
assert f.q.p.s.w.p.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.s: B = None
        self.q: A = None
        self.txt = txt

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

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

h = A("h")
b = B("b")
j = C("j")
k = C("k")
g = B("g")
d = C("d")
n = B("n")
f = B("f")
m = A("m")

h.r = m
h.q = m
h.s = n
b.q = j
b.w = d
j.p = h
j.v = d
k.p = h
k.v = j
g.q = k
g.w = j
d.p = m
d.v = j
n.q = d
n.w = j
f.q = d
f.w = j
m.r = h
m.q = h
m.s = g
assert f.q.p.s.w.p.r.s.txt == "g"