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

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

h = A("h")
c = B("c")
m = B("m")
n = A("n")
b = A("b")
k = B("k")
d = A("d")

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

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

h = A("h")
c = B("c")
m = B("m")
n = A("n")
b = A("b")
k = B("k")
d = A("d")

h.q = b
h.w = k
c.r = h
c.q = b
m.r = d
m.q = h
n.q = d
n.w = m
b.q = h
b.w = m
k.r = n
k.q = d
d.q = b
d.w = m
assert h.q.w.r.txt == "d"