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

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

k = A("k")
n = B("n")
m = A("m")
l = B("l")
h = B("h")

k.v = m
k.p = m
n.q = h
m.v = k
m.p = k
l.q = h
h.q = n
assert n.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: A = None
        self.txt = txt

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

k = A("k")
n = B("n")
m = A("m")
l = B("l")
h = B("h")

k.v = m
k.p = m
n.q = h
m.v = k
m.p = k
l.q = h
h.q = n
assert n.q.q.q.q.txt == "n"