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

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

n = A("n")
g = B("g")
c = B("c")
f = A("f")
b = A("b")
i = A("i")

n.v = f
n.u = i
g.q = c
g.r = i
c.q = g
c.r = b
f.v = n
f.u = b
b.v = f
b.u = f
i.v = f
i.u = b
assert g.r.u.u.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.u: A = None
        self.txt = txt

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

n = A("n")
g = B("g")
c = B("c")
f = A("f")
b = A("b")
i = A("i")

n.v = f
n.u = i
g.q = c
g.r = i
c.q = g
c.r = b
f.v = n
f.u = b
b.v = f
b.u = f
i.v = f
i.u = b
assert g.r.u.u.v.v.txt == "f"