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

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

b = A("b")
k = B("k")
m = A("m")
g = B("g")
h = A("h")
i = B("i")

b.r = m
b.u = m
k.q = i
m.r = h
m.u = h
g.q = k
h.r = b
h.u = m
i.q = g
assert h.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: A = None
        self.txt = txt

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

b = A("b")
k = B("k")
m = A("m")
g = B("g")
h = A("h")
i = B("i")

b.r = m
b.u = m
k.q = i
m.r = h
m.u = h
g.q = k
h.r = b
h.u = m
i.q = g
assert h.u.u.u.txt == "m"