class A:
    def __init__(self, txt: str):
        self.p: E = None
        self.q: D = None
        self.t: B = None
        self.u: E = None
        self.r: C = None
        self.txt = txt

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

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

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

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

b = A("b")
d = B("d")
h = C("h")
g = D("g")
c = E("c")

b.p = c
b.u = c
b.q = g
b.t = d
b.r = h
d.u = h
d.p = c
h.r = g
g.w = h
g.r = d
g.x = b
c.s = d
assert c.s.p.s.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: E = None
        self.q: D = None
        self.t: B = None
        self.u: E = None
        self.r: C = None
        self.txt = txt

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

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

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

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

b = A("b")
d = B("d")
h = C("h")
g = D("g")
c = E("c")

b.p = c
b.u = c
b.q = g
b.t = d
b.r = h
d.u = h
d.p = c
h.r = g
g.w = h
g.r = d
g.x = b
c.s = d
assert c.s.p.s.u.r.txt == "g"