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

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

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

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

h = A("h")
d = B("d")
f = C("f")
k = D("k")

h.v = d
h.p = d
d.s = f
d.o = f
f.p = h
k.r = d
assert k.r.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.p: B = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
f = C("f")
k = D("k")

h.v = d
h.p = d
d.s = f
d.o = f
f.p = h
k.r = d
assert k.r.s.p.txt == "h"