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

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

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

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

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

a.r = i
a.x = i
b.v = i
b.o = h
b.r = e
m.y = h
h.s = e
h.p = e
i.r = a
i.x = a
e.v = a
e.o = h
e.r = b
assert b.v.x.r.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

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

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

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

a.r = i
a.x = i
b.v = i
b.o = h
b.r = e
m.y = h
h.s = e
h.p = e
i.r = a
i.x = a
e.v = a
e.o = h
e.r = b
assert b.v.x.r.x.x.txt == "i"