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

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

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

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

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

j.o = d
j.r = k
j.w = b
d.y = e
d.w = j
b.p = n
b.w = a
b.v = k
b.t = d
h.t = g
h.p = b
n.t = d
n.p = a
f.y = e
f.w = j
g.y = e
g.w = j
a.p = k
a.w = b
a.v = h
a.t = d
e.y = f
e.w = j
k.t = d
k.p = a
assert a.p.t.y.w.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: D = None
        self.w: C = None
        self.txt = txt

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

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

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

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

j.o = d
j.r = k
j.w = b
d.y = e
d.w = j
b.p = n
b.w = a
b.v = k
b.t = d
h.t = g
h.p = b
n.t = d
n.p = a
f.y = e
f.w = j
g.y = e
g.w = j
a.p = k
a.w = b
a.v = h
a.t = d
e.y = f
e.w = j
k.t = d
k.p = a
assert a.p.t.y.w.r.t.txt == "d"