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

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

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

l.q = a
l.w = a
f.v = b
b.v = d
k.v = d
g.v = h
h.v = b
a.q = l
a.w = l
d.v = b
assert l.w.w.w.w.q.w.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.w: A = None
        self.txt = txt

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

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

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