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

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

a = A("a")
g = B("g")
f = A("f")
j = B("j")
k = B("k")
n = A("n")
h = B("h")
d = B("d")
l = A("l")
b = B("b")

a.q = f
g.v = l
f.q = l
j.v = f
k.v = f
n.q = l
h.v = n
d.v = a
l.q = f
b.v = n
assert g.v.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.v: A = None
        self.txt = txt

a = A("a")
g = B("g")
f = A("f")
j = B("j")
k = B("k")
n = A("n")
h = B("h")
d = B("d")
l = A("l")
b = B("b")

a.q = f
g.v = l
f.q = l
j.v = f
k.v = f
n.q = l
h.v = n
d.v = a
l.q = f
b.v = n
assert g.v.q.q.q.q.txt == "l"