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

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

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

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

b = A("b")
k = B("k")
m = C("m")
n = D("n")
h = B("h")
g = D("g")

b.r = k
b.y = g
k.t = h
k.s = h
k.p = m
k.v = m
m.o = b
m.y = h
m.x = h
m.z = k
n.y = m
n.r = m
n.x = b
n.v = h
h.t = k
h.s = k
h.p = m
h.v = m
g.y = m
g.r = m
g.x = b
g.v = h
assert m.o.r.v.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: D = None
        self.txt = txt

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

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

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

b = A("b")
k = B("k")
m = C("m")
n = D("n")
h = B("h")
g = D("g")

b.r = k
b.y = g
k.t = h
k.s = h
k.p = m
k.v = m
m.o = b
m.y = h
m.x = h
m.z = k
n.y = m
n.r = m
n.x = b
n.v = h
h.t = k
h.s = k
h.p = m
h.v = m
g.y = m
g.r = m
g.x = b
g.v = h
assert m.o.r.v.o.txt == "b"