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

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

n = A("n")
k = B("k")
l = B("l")
a = B("a")
h = B("h")
e = B("e")
f = B("f")
d = A("d")
b = B("b")
j = A("j")

n.q = k
k.p = d
k.q = h
l.p = d
l.q = k
a.p = j
a.q = l
h.p = j
h.q = l
e.p = n
e.q = a
f.p = j
f.q = k
d.q = b
b.p = j
b.q = k
j.q = f
assert f.p.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

n = A("n")
k = B("k")
l = B("l")
a = B("a")
h = B("h")
e = B("e")
f = B("f")
d = A("d")
b = B("b")
j = A("j")

n.q = k
k.p = d
k.q = h
l.p = d
l.q = k
a.p = j
a.q = l
h.p = j
h.q = l
e.p = n
e.q = a
f.p = j
f.q = k
d.q = b
b.p = j
b.q = k
j.q = f
assert f.p.q.p.q.txt == "f"