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

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

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

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

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

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

c.u = j
c.p = f
e.y = g
d.r = m
d.y = g
f.r = j
a.r = e
a.t = b
j.r = f
g.u = j
g.p = j
b.r = e
b.t = a
m.r = d
m.y = c
assert m.r.r.r.r.r.y.p.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.p: D = None
        self.txt = txt

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

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

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

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

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

c.u = j
c.p = f
e.y = g
d.r = m
d.y = g
f.r = j
a.r = e
a.t = b
j.r = f
g.u = j
g.p = j
b.r = e
b.t = a
m.r = d
m.y = c
assert m.r.r.r.r.r.y.p.r.r.txt == "j"