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

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: A = None
        self.o: B = None
        self.txt = txt

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

g = A("g")
e = B("e")
i = C("i")
k = D("k")
b = A("b")

g.r = k
g.v = b
g.w = b
e.r = b
e.o = i
i.s = e
i.o = e
i.w = b
k.v = i
k.x = i
b.r = k
b.v = g
b.w = g
assert k.v.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.v: A = None
        self.w: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: A = None
        self.o: B = None
        self.txt = txt

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

g = A("g")
e = B("e")
i = C("i")
k = D("k")
b = A("b")

g.r = k
g.v = b
g.w = b
e.r = b
e.o = i
i.s = e
i.o = e
i.w = b
k.v = i
k.x = i
b.r = k
b.v = g
b.w = g
assert k.v.s.r.txt == "b"