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

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

n = A("n")
j = B("j")
f = A("f")
l = A("l")
k = A("k")
m = B("m")

n.p = k
n.q = m
j.y = l
f.p = n
f.q = m
l.p = k
l.q = j
k.p = f
k.q = j
m.y = l
assert l.p.q.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: B = None
        self.txt = txt

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

n = A("n")
j = B("j")
f = A("f")
l = A("l")
k = A("k")
m = B("m")

n.p = k
n.q = m
j.y = l
f.p = n
f.q = m
l.p = k
l.q = j
k.p = f
k.q = j
m.y = l
assert l.p.q.y.q.y.txt == "l"