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

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

b = A("b")
h = B("h")
c = B("c")
k = B("k")
j = A("j")

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

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

b = A("b")
h = B("h")
c = B("c")
k = B("k")
j = A("j")

b.q = h
b.u = j
h.w = b
c.w = j
k.w = b
j.q = h
j.u = b
assert c.w.q.w.txt == "b"