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

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

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

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

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

h.v = d
h.o = n
g.p = h
g.r = h
g.t = h
n.r = g
n.u = h
n.w = d
d.w = n
assert h.o.r.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.o: C = None
        self.txt = txt

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

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

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

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

h.v = d
h.o = n
g.p = h
g.r = h
g.t = h
n.r = g
n.u = h
n.w = d
d.w = n
assert h.o.r.t.v.txt == "d"