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

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

i = A("i")
c = B("c")
n = B("n")
g = A("g")
j = A("j")
m = A("m")
a = A("a")
b = B("b")
k = A("k")
d = B("d")

i.q = c
c.p = n
c.x = n
n.p = d
n.x = d
g.q = d
j.q = d
m.q = d
a.q = n
b.p = c
b.x = n
k.q = d
d.p = b
d.x = n
assert k.q.p.x.p.x.p.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
n = B("n")
g = A("g")
j = A("j")
m = A("m")
a = A("a")
b = B("b")
k = A("k")
d = B("d")

i.q = c
c.p = n
c.x = n
n.p = d
n.x = d
g.q = d
j.q = d
m.q = d
a.q = n
b.p = c
b.x = n
k.q = d
d.p = b
d.x = n
assert k.q.p.x.p.x.p.p.p.x.txt == "n"