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

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

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

b = A("b")
j = B("j")
f = C("f")
m = B("m")
a = C("a")
h = B("h")

b.y = a
j.v = a
f.q = b
f.r = a
f.y = a
m.v = a
a.q = b
a.r = f
a.y = f
h.v = a
assert m.v.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
f = C("f")
m = B("m")
a = C("a")
h = B("h")

b.y = a
j.v = a
f.q = b
f.r = a
f.y = a
m.v = a
a.q = b
a.r = f
a.y = f
h.v = a
assert m.v.q.y.q.txt == "b"