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

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

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

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

f = A("f")
n = B("n")
j = C("j")
a = D("a")
g = D("g")
d = C("d")
e = A("e")
b = D("b")

f.r = n
n.r = d
j.s = a
j.x = n
j.o = d
a.p = n
g.p = n
d.s = g
d.x = n
d.o = j
e.r = n
b.p = n
assert e.r.r.o.s.p.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

f = A("f")
n = B("n")
j = C("j")
a = D("a")
g = D("g")
d = C("d")
e = A("e")
b = D("b")

f.r = n
n.r = d
j.s = a
j.x = n
j.o = d
a.p = n
g.p = n
d.s = g
d.x = n
d.o = j
e.r = n
b.p = n
assert e.r.r.o.s.p.r.o.txt == "j"