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

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

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

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

f = A("f")
c = B("c")
d = C("d")
k = D("k")
e = A("e")
j = A("j")

f.x = c
f.r = k
f.o = k
c.v = d
d.r = c
k.r = f
e.x = c
e.r = k
e.o = k
j.x = c
j.r = k
j.o = k
assert k.r.x.v.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: D = None
        self.o: D = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
d = C("d")
k = D("k")
e = A("e")
j = A("j")

f.x = c
f.r = k
f.o = k
c.v = d
d.r = c
k.r = f
e.x = c
e.r = k
e.o = k
j.x = c
j.r = k
j.o = k
assert k.r.x.v.r.v.r.txt == "c"