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

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

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

f = A("f")
e = B("e")
m = C("m")
b = B("b")

f.u = e
e.v = m
e.p = m
e.x = b
m.q = b
m.r = e
b.v = m
b.p = m
b.x = e
assert b.v.r.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
m = C("m")
b = B("b")

f.u = e
e.v = m
e.p = m
e.x = b
m.q = b
m.r = e
b.v = m
b.p = m
b.x = e
assert b.v.r.x.p.txt == "m"