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

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

c = A("c")
f = B("f")
d = B("d")
l = A("l")
k = A("k")
m = B("m")
n = B("n")

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

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

c = A("c")
f = B("f")
d = B("d")
l = A("l")
k = A("k")
m = B("m")
n = B("n")

c.q = m
f.w = c
f.v = l
d.w = c
d.v = k
l.q = m
k.q = f
m.w = c
m.v = c
n.w = l
n.v = c
assert d.w.q.w.q.txt == "m"