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

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

l = A("l")
a = B("a")
i = B("i")
f = A("f")

l.t = a
l.r = f
a.u = f
a.q = l
i.u = l
i.q = l
f.t = i
f.r = l
assert a.q.r.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: A = None
        self.txt = txt

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

l = A("l")
a = B("a")
i = B("i")
f = A("f")

l.t = a
l.r = f
a.u = f
a.q = l
i.u = l
i.q = l
f.t = i
f.r = l
assert a.q.r.t.q.txt == "l"