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

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

i = A("i")
b = B("b")
n = A("n")
f = B("f")

i.q = n
i.y = n
b.u = f
n.q = i
n.y = i
f.u = b
assert i.q.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.y: A = None
        self.txt = txt

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

i = A("i")
b = B("b")
n = A("n")
f = B("f")

i.q = n
i.y = n
b.u = f
n.q = i
n.y = i
f.u = b
assert i.q.y.y.txt == "n"