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

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

i = A("i")
l = B("l")
k = B("k")
g = A("g")

i.r = k
i.u = g
l.s = g
l.x = k
k.s = g
k.x = l
g.r = k
g.u = i
assert i.u.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: A = None
        self.txt = txt

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

i = A("i")
l = B("l")
k = B("k")
g = A("g")

i.r = k
i.u = g
l.s = g
l.x = k
k.s = g
k.x = l
g.r = k
g.u = i
assert i.u.r.s.txt == "g"