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

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

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

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

h = A("h")
j = B("j")
a = C("a")
m = D("m")
i = C("i")
k = A("k")
b = C("b")

h.y = k
h.v = m
h.r = j
j.y = i
a.q = k
a.x = i
m.p = j
m.x = k
i.q = h
i.x = a
k.y = h
k.v = m
k.r = j
b.q = k
b.x = i
assert h.y.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: D = None
        self.r: B = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
a = C("a")
m = D("m")
i = C("i")
k = A("k")
b = C("b")

h.y = k
h.v = m
h.r = j
j.y = i
a.q = k
a.x = i
m.p = j
m.x = k
i.q = h
i.x = a
k.y = h
k.v = m
k.r = j
b.q = k
b.x = i
assert h.y.y.v.txt == "m"