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

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

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

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

i = A("i")
j = B("j")
d = C("d")
f = D("f")
a = A("a")
m = D("m")
l = A("l")
h = B("h")

i.p = h
j.v = h
j.u = f
j.x = d
j.y = d
d.p = j
f.y = d
f.w = l
a.p = h
m.y = d
m.w = l
l.p = h
h.v = j
h.u = m
h.x = d
h.y = d
assert h.v.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

i = A("i")
j = B("j")
d = C("d")
f = D("f")
a = A("a")
m = D("m")
l = A("l")
h = B("h")

i.p = h
j.v = h
j.u = f
j.x = d
j.y = d
d.p = j
f.y = d
f.w = l
a.p = h
m.y = d
m.w = l
l.p = h
h.v = j
h.u = m
h.x = d
h.y = d
assert h.v.v.y.txt == "d"