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

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

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

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

d = A("d")
m = B("m")
a = C("a")
g = D("g")
i = D("i")
b = B("b")

d.x = a
d.o = a
d.v = g
d.t = b
m.r = b
m.t = d
a.r = i
g.u = m
i.u = b
b.r = m
b.t = d
assert b.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.v: D = None
        self.o: C = None
        self.t: B = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
a = C("a")
g = D("g")
i = D("i")
b = B("b")

d.x = a
d.o = a
d.v = g
d.t = b
m.r = b
m.t = d
a.r = i
g.u = m
i.u = b
b.r = m
b.t = d
assert b.r.r.r.r.txt == "b"