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

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

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

class D:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: E = None
        self.w: E = None
        self.t: A = None
        self.r: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

f = A("f")
g = B("g")
d = C("d")
b = D("b")
n = E("n")
h = C("h")

f.v = d
g.v = f
g.y = h
d.y = b
d.s = h
b.x = f
b.t = f
b.y = n
b.w = n
b.r = n
n.v = b
h.y = b
h.s = d
assert h.y.x.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: E = None
        self.w: E = None
        self.t: A = None
        self.r: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

f = A("f")
g = B("g")
d = C("d")
b = D("b")
n = E("n")
h = C("h")

f.v = d
g.v = f
g.y = h
d.y = b
d.s = h
b.x = f
b.t = f
b.y = n
b.w = n
b.r = n
n.v = b
h.y = b
h.s = d
assert h.y.x.v.y.txt == "b"