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

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

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

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

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

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

j.r = c
n.r = e
k.r = i
c.r = g
g.r = j
e.r = i
i.r = n
assert e.r.r.r.r.txt == "i"