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

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

i = A("i")
j = B("j")
n = B("n")
a = A("a")
k = A("k")
m = B("m")

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

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

i = A("i")
j = B("j")
n = B("n")
a = A("a")
k = A("k")
m = B("m")

i.p = m
i.q = m
j.t = i
j.x = a
n.t = i
n.x = a
a.p = n
a.q = m
k.p = n
k.q = m
m.t = a
m.x = a
assert n.t.q.t.q.txt == "m"