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

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: B = None
        self.txt = txt

n = A("n")
j = B("j")
h = A("h")
a = A("a")
g = A("g")
i = B("i")
d = B("d")
k = B("k")

n.q = g
n.r = k
j.y = k
j.p = d
h.q = n
h.r = i
a.q = h
a.r = i
g.q = n
g.r = i
i.y = k
i.p = j
d.y = i
d.p = i
k.y = i
k.p = d
assert g.q.r.p.y.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: B = None
        self.txt = txt

n = A("n")
j = B("j")
h = A("h")
a = A("a")
g = A("g")
i = B("i")
d = B("d")
k = B("k")

n.q = g
n.r = k
j.y = k
j.p = d
h.q = n
h.r = i
a.q = h
a.r = i
g.q = n
g.r = i
i.y = k
i.p = j
d.y = i
d.p = i
k.y = i
k.p = d
assert g.q.r.p.y.p.p.p.txt == "i"