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

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

k = A("k")
c = B("c")
g = A("g")
n = B("n")
i = B("i")
a = A("a")
j = A("j")

k.s = i
k.r = a
c.x = j
g.s = c
g.r = j
n.x = k
i.x = k
a.s = i
a.r = j
j.s = c
j.r = g
assert i.x.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
c = B("c")
g = A("g")
n = B("n")
i = B("i")
a = A("a")
j = A("j")

k.s = i
k.r = a
c.x = j
g.s = c
g.r = j
n.x = k
i.x = k
a.s = i
a.r = j
j.s = c
j.r = g
assert i.x.r.s.txt == "i"