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

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

c = A("c")
g = B("g")
l = A("l")
i = B("i")
d = A("d")
n = B("n")

c.r = l
g.s = i
l.r = d
i.s = n
d.r = l
n.s = i
assert g.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

c = A("c")
g = B("g")
l = A("l")
i = B("i")
d = A("d")
n = B("n")

c.r = l
g.s = i
l.r = d
i.s = n
d.r = l
n.s = i
assert g.s.s.s.txt == "i"