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

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

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

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

n = A("n")
a = B("a")
k = C("k")
b = D("b")
f = A("f")
g = C("g")

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

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

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

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

n = A("n")
a = B("a")
k = C("k")
b = D("b")
f = A("f")
g = C("g")

n.o = f
n.r = b
n.w = b
n.y = g
a.t = n
a.p = b
k.y = b
b.p = a
f.o = n
f.r = b
f.w = b
f.y = g
g.y = b
assert k.y.p.p.p.p.txt == "b"