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

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

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

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

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

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

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

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

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

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

b.p = i
b.x = i
b.q = f
b.v = a
i.p = d
i.r = f
f.t = a
f.q = b
d.t = b
d.v = a
d.u = f
a.t = b
a.v = d
a.u = f
assert b.v.v.t.txt == "b"