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

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

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

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

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

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

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