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

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

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

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

b = A("b")
a = B("a")
f = C("f")
g = D("g")
j = D("j")

b.q = f
b.v = f
b.p = f
a.u = f
f.o = b
g.y = j
j.y = g
assert f.o.v.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.v: C = None
        self.p: C = None
        self.txt = txt

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

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

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

b = A("b")
a = B("a")
f = C("f")
g = D("g")
j = D("j")

b.q = f
b.v = f
b.p = f
a.u = f
f.o = b
g.y = j
j.y = g
assert f.o.v.o.q.txt == "f"