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

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

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

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

l = A("l")
g = B("g")
c = C("c")
k = D("k")
i = B("i")
e = B("e")

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

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

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

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

l = A("l")
g = B("g")
c = C("c")
k = D("k")
i = B("i")
e = B("e")

l.r = i
g.s = l
g.u = e
c.y = e
k.s = c
i.s = l
i.u = g
e.s = l
e.u = g
assert i.s.r.s.r.s.txt == "l"