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

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

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

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

h = A("h")
l = B("l")
i = C("i")
m = D("m")
g = A("g")
d = D("d")

h.r = g
h.z = i
l.y = h
i.p = m
m.v = d
m.x = h
m.p = h
m.o = l
g.r = h
g.z = i
d.v = m
d.x = h
d.p = h
d.o = l
assert m.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: C = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
i = C("i")
m = D("m")
g = A("g")
d = D("d")

h.r = g
h.z = i
l.y = h
i.p = m
m.v = d
m.x = h
m.p = h
m.o = l
g.r = h
g.z = i
d.v = m
d.x = h
d.p = h
d.o = l
assert m.x.r.r.txt == "h"