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

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

m = A("m")
c = B("c")
n = B("n")
a = A("a")
g = A("g")
b = A("b")
d = A("d")
h = A("h")
f = B("f")

m.p = g
c.q = h
n.q = a
a.p = d
g.p = h
b.p = a
d.p = m
h.p = a
f.q = a
assert c.q.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

m = A("m")
c = B("c")
n = B("n")
a = A("a")
g = A("g")
b = A("b")
d = A("d")
h = A("h")
f = B("f")

m.p = g
c.q = h
n.q = a
a.p = d
g.p = h
b.p = a
d.p = m
h.p = a
f.q = a
assert c.q.p.p.p.p.p.p.txt == "a"