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

class B:
    def __init__(self, txt: str):
        self.r: E = None
        self.z: D = None
        self.s: A = None
        self.w: A = None
        self.txt = txt

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

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

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

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

b.r = d
a.r = j
a.z = f
a.s = b
a.w = b
d.z = c
d.t = b
d.r = b
f.t = a
j.z = b
j.w = f
j.t = d
j.q = a
g.z = c
g.t = b
g.r = b
c.z = b
c.w = f
c.t = g
c.q = a
assert d.t.r.z.q.z.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: E = None
        self.z: D = None
        self.s: A = None
        self.w: A = None
        self.txt = txt

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

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

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

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

b.r = d
a.r = j
a.z = f
a.s = b
a.w = b
d.z = c
d.t = b
d.r = b
f.t = a
j.z = b
j.w = f
j.t = d
j.q = a
g.z = c
g.t = b
g.r = b
c.z = b
c.w = f
c.t = g
c.q = a
assert d.t.r.z.q.z.t.r.txt == "j"