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

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

j = A("j")
k = B("k")
n = A("n")
h = A("h")
a = B("a")

j.q = h
k.u = a
k.v = a
n.q = h
h.q = n
a.u = k
a.v = k
assert n.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

j = A("j")
k = B("k")
n = A("n")
h = A("h")
a = B("a")

j.q = h
k.u = a
k.v = a
n.q = h
h.q = n
a.u = k
a.v = k
assert n.q.q.q.q.txt == "n"