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

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

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

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

e = A("e")
g = B("g")
m = C("m")
d = D("d")
j = A("j")
l = D("l")

e.s = m
g.p = m
g.o = d
m.t = g
m.r = g
m.p = j
m.y = e
d.r = e
j.s = m
l.r = j
assert d.r.s.r.p.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

e = A("e")
g = B("g")
m = C("m")
d = D("d")
j = A("j")
l = D("l")

e.s = m
g.p = m
g.o = d
m.t = g
m.r = g
m.p = j
m.y = e
d.r = e
j.s = m
l.r = j
assert d.r.s.r.p.p.s.txt == "m"