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

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

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

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

g = A("g")
a = B("a")
c = C("c")
n = D("n")
h = D("h")
e = B("e")
i = D("i")
m = B("m")
f = A("f")

g.s = e
g.r = f
g.p = a
a.o = f
c.v = i
n.r = m
h.r = m
e.o = f
i.r = m
m.o = f
f.s = e
f.p = e
f.r = g
assert g.r.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: A = None
        self.p: B = None
        self.txt = txt

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

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

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

g = A("g")
a = B("a")
c = C("c")
n = D("n")
h = D("h")
e = B("e")
i = D("i")
m = B("m")
f = A("f")

g.s = e
g.r = f
g.p = a
a.o = f
c.v = i
n.r = m
h.r = m
e.o = f
i.r = m
m.o = f
f.s = e
f.p = e
f.r = g
assert g.r.p.o.txt == "f"