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

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

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

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

i = A("i")
h = B("h")
g = C("g")
n = D("n")
b = C("b")
m = C("m")
d = C("d")

i.y = h
h.p = n
h.t = i
g.r = h
g.y = d
g.p = n
n.p = i
b.r = h
b.y = d
b.p = n
m.r = h
m.y = b
m.p = n
d.r = h
d.y = m
d.p = n
assert i.y.t.y.p.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

i = A("i")
h = B("h")
g = C("g")
n = D("n")
b = C("b")
m = C("m")
d = C("d")

i.y = h
h.p = n
h.t = i
g.r = h
g.y = d
g.p = n
n.p = i
b.r = h
b.y = d
b.p = n
m.r = h
m.y = b
m.p = n
d.r = h
d.y = m
d.p = n
assert i.y.t.y.p.p.y.p.txt == "n"