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

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

j = A("j")
d = B("d")
k = A("k")
l = B("l")
i = B("i")
g = B("g")
f = A("f")
m = B("m")

j.q = i
j.p = k
d.u = j
d.t = f
k.q = m
k.p = j
l.u = f
l.t = k
i.u = k
i.t = j
g.u = k
g.t = f
f.q = g
f.p = k
m.u = f
m.t = f
assert m.t.q.u.p.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
d = B("d")
k = A("k")
l = B("l")
i = B("i")
g = B("g")
f = A("f")
m = B("m")

j.q = i
j.p = k
d.u = j
d.t = f
k.q = m
k.p = j
l.u = f
l.t = k
i.u = k
i.t = j
g.u = k
g.t = f
f.q = g
f.p = k
m.u = f
m.t = f
assert m.t.q.u.p.q.u.txt == "k"