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

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

j = A("j")
i = B("i")
d = A("d")
e = B("e")
c = B("c")

j.y = e
j.q = d
i.q = c
i.u = j
d.y = i
d.q = j
e.q = i
e.u = d
c.q = i
c.u = j
assert i.u.y.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: A = None
        self.txt = txt

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

j = A("j")
i = B("i")
d = A("d")
e = B("e")
c = B("c")

j.y = e
j.q = d
i.q = c
i.u = j
d.y = i
d.q = j
e.q = i
e.u = d
c.q = i
c.u = j
assert i.u.y.q.u.q.txt == "d"