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

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

h = A("h")
m = B("m")
n = B("n")
g = B("g")
c = B("c")
b = B("b")

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

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

h = A("h")
m = B("m")
n = B("n")
g = B("g")
c = B("c")
b = B("b")

h.q = b
h.u = c
m.w = h
n.w = h
g.w = h
c.w = h
b.w = h
assert n.w.u.w.txt == "h"