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

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: E = None
        self.txt = txt

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

g = A("g")
a = B("a")
c = C("c")
d = D("d")
n = E("n")
j = C("j")

g.x = n
a.r = n
a.t = g
a.o = g
a.s = j
c.o = a
d.z = j
d.v = n
n.p = a
j.o = a
assert a.s.o.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: E = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: E = None
        self.txt = txt

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

g = A("g")
a = B("a")
c = C("c")
d = D("d")
n = E("n")
j = C("j")

g.x = n
a.r = n
a.t = g
a.o = g
a.s = j
c.o = a
d.z = j
d.v = n
n.p = a
j.o = a
assert a.s.o.r.p.txt == "a"