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

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

b = A("b")
j = B("j")
f = A("f")
h = A("h")
m = A("m")
i = B("i")
c = B("c")

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

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

b = A("b")
j = B("j")
f = A("f")
h = A("h")
m = A("m")
i = B("i")
c = B("c")

b.u = m
b.q = j
j.u = f
j.w = m
f.u = h
f.q = i
h.u = b
h.q = i
m.u = b
m.q = j
i.u = f
i.w = m
c.u = b
c.w = m
assert i.w.u.u.q.w.u.txt == "b"