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

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

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

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

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

d.o = g
d.s = n
c.p = g
c.r = k
n.z = f
k.x = n
k.y = j
f.x = n
f.y = e
g.p = c
g.r = f
j.o = g
j.s = n
b.p = g
b.r = f
e.o = b
e.s = n
assert b.r.x.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: C = None
        self.txt = txt

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

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

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

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

d.o = g
d.s = n
c.p = g
c.r = k
n.z = f
k.x = n
k.y = j
f.x = n
f.y = e
g.p = c
g.r = f
j.o = g
j.s = n
b.p = g
b.r = f
e.o = b
e.s = n
assert b.r.x.z.x.z.txt == "f"