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

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

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

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

f = A("f")
g = B("g")
l = C("l")
n = D("n")
k = B("k")

f.v = l
f.y = l
f.x = l
g.x = k
g.r = k
l.u = f
l.y = n
n.y = f
n.q = f
n.v = f
k.x = g
k.r = g
assert n.y.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.y: C = None
        self.x: C = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
l = C("l")
n = D("n")
k = B("k")

f.v = l
f.y = l
f.x = l
g.x = k
g.r = k
l.u = f
l.y = n
n.y = f
n.q = f
n.v = f
k.x = g
k.r = g
assert n.y.x.u.txt == "f"