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

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

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

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

b = A("b")
m = B("m")
f = C("f")
l = D("l")
j = B("j")

b.y = f
b.r = f
m.u = l
m.v = b
f.w = b
f.s = b
f.r = j
l.v = j
j.u = l
j.v = b
assert b.y.r.v.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.r: C = None
        self.txt = txt

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

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

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

b = A("b")
m = B("m")
f = C("f")
l = D("l")
j = B("j")

b.y = f
b.r = f
m.u = l
m.v = b
f.w = b
f.s = b
f.r = j
l.v = j
j.u = l
j.v = b
assert b.y.r.v.y.r.txt == "j"