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

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

d = A("d")
i = B("i")
c = B("c")
b = B("b")
f = B("f")
k = B("k")
n = B("n")
g = A("g")
m = A("m")
a = A("a")

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

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

d = A("d")
i = B("i")
c = B("c")
b = B("b")
f = B("f")
k = B("k")
n = B("n")
g = A("g")
m = A("m")
a = A("a")

d.q = m
i.w = k
i.v = c
c.w = f
c.v = i
b.w = f
b.v = c
f.w = c
f.v = i
k.w = i
k.v = f
n.w = k
n.v = b
g.q = m
m.q = g
a.q = d
assert k.v.v.w.txt == "k"