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

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

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

f = A("f")
j = B("j")
g = C("g")
d = B("d")
e = B("e")
h = B("h")
i = C("i")
n = A("n")
c = A("c")
m = B("m")

f.p = g
f.q = g
f.y = e
j.x = g
g.q = i
g.x = i
d.x = g
e.x = g
h.x = i
i.q = g
i.x = g
n.p = g
n.q = g
n.y = h
c.p = i
c.q = i
c.y = m
m.x = g
assert d.x.q.x.x.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.y: B = None
        self.txt = txt

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

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

f = A("f")
j = B("j")
g = C("g")
d = B("d")
e = B("e")
h = B("h")
i = C("i")
n = A("n")
c = A("c")
m = B("m")

f.p = g
f.q = g
f.y = e
j.x = g
g.q = i
g.x = i
d.x = g
e.x = g
h.x = i
i.q = g
i.x = g
n.p = g
n.q = g
n.y = h
c.p = i
c.q = i
c.y = m
m.x = g
assert d.x.q.x.x.q.q.q.txt == "g"