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

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

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

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

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

j.r = e
j.w = f
j.y = d
d.w = b
d.v = f
d.x = f
f.y = d
f.r = j
b.p = e
e.r = j
e.w = f
e.y = d
assert b.p.y.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: C = None
        self.y: B = None
        self.txt = txt

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

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

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

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

j.r = e
j.w = f
j.y = d
d.w = b
d.v = f
d.x = f
f.y = d
f.r = j
b.p = e
e.r = j
e.w = f
e.y = d
assert b.p.y.v.r.txt == "j"