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

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

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

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

g = A("g")
j = B("j")
d = C("d")
i = D("i")
m = A("m")
c = C("c")
l = B("l")
b = A("b")

g.r = d
g.s = l
g.y = m
j.s = l
d.p = c
i.p = g
i.t = l
i.x = j
m.r = c
m.s = j
m.y = g
c.p = d
l.s = j
b.r = c
b.s = l
b.y = m
assert d.p.p.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: B = None
        self.y: A = None
        self.txt = txt

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

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

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

g = A("g")
j = B("j")
d = C("d")
i = D("i")
m = A("m")
c = C("c")
l = B("l")
b = A("b")

g.r = d
g.s = l
g.y = m
j.s = l
d.p = c
i.p = g
i.t = l
i.x = j
m.r = c
m.s = j
m.y = g
c.p = d
l.s = j
b.r = c
b.s = l
b.y = m
assert d.p.p.p.p.p.p.p.p.txt == "d"