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

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

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

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

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

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

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

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

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