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

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

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

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

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

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

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

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

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

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

i.v = a
l.r = k
l.y = a
g.o = b
g.v = a
a.r = i
a.x = g
k.r = l
k.y = a
b.v = a
assert g.v.x.v.r.v.r.txt == "i"